openlinear 0.1.3
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/README.md +97 -0
- package/bin/openlinear.js +21 -0
- package/dist/chunk-5E4TN2YB.mjs +87 -0
- package/dist/chunk-HARBMOVK.mjs +107 -0
- package/dist/chunk-P3FFNK6N.mjs +103 -0
- package/dist/config/index.d.mts +33 -0
- package/dist/config/index.d.ts +33 -0
- package/dist/config/index.js +119 -0
- package/dist/config/index.mjs +18 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +304 -0
- package/dist/index.mjs +42 -0
- package/dist/types/index.d.mts +70 -0
- package/dist/types/index.d.ts +70 -0
- package/dist/types/index.js +140 -0
- package/dist/types/index.mjs +20 -0
- package/dist/validation/index.d.mts +74 -0
- package/dist/validation/index.d.ts +74 -0
- package/dist/validation/index.js +137 -0
- package/dist/validation/index.mjs +22 -0
- package/package.json +61 -0
- package/scripts/postinstall.js +65 -0
- package/src/config/feature-flags.ts +121 -0
- package/src/config/index.ts +1 -0
- package/src/index.ts +6 -0
- package/src/types/execution-metadata.ts +116 -0
- package/src/types/index.ts +1 -0
- package/src/validation/index.ts +1 -0
- package/src/validation/security.ts +113 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ErrorCategory: () => ErrorCategory2,
|
|
24
|
+
ExecutionMetadataSyncSchema: () => ExecutionMetadataSyncSchema2,
|
|
25
|
+
ExecutionStatus: () => ExecutionStatus2,
|
|
26
|
+
FORBIDDEN_SYNC_FIELDS: () => FORBIDDEN_SYNC_FIELDS2,
|
|
27
|
+
FeatureFlagsSchema: () => FeatureFlagsSchema,
|
|
28
|
+
checkExecutionMetadataSync: () => checkExecutionMetadataSync,
|
|
29
|
+
getFeatureFlags: () => getFeatureFlags,
|
|
30
|
+
getMigrationPhase: () => getMigrationPhase,
|
|
31
|
+
isForbiddenField: () => isForbiddenField,
|
|
32
|
+
isLocalExecutionEnabled: () => isLocalExecutionEnabled,
|
|
33
|
+
isServerExecutionEnabled: () => isServerExecutionEnabled,
|
|
34
|
+
parseFeatureFlags: () => parseFeatureFlags,
|
|
35
|
+
safeValidateExecutionMetadataSync: () => safeValidateExecutionMetadataSync,
|
|
36
|
+
sanitizePayload: () => sanitizePayload,
|
|
37
|
+
validateExecutionMetadataMiddleware: () => validateExecutionMetadataMiddleware,
|
|
38
|
+
validateExecutionMetadataSync: () => validateExecutionMetadataSync,
|
|
39
|
+
validateFlagConfiguration: () => validateFlagConfiguration
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(index_exports);
|
|
42
|
+
|
|
43
|
+
// src/config/feature-flags.ts
|
|
44
|
+
var import_zod = require("zod");
|
|
45
|
+
var FeatureFlagsSchema = import_zod.z.object({
|
|
46
|
+
LOCAL_EXECUTION_ENABLED: import_zod.z.enum(["true", "false"]).default("false").transform((v) => v === "true"),
|
|
47
|
+
SERVER_EXECUTION_ENABLED: import_zod.z.enum(["true", "false"]).default("true").transform((v) => v === "true"),
|
|
48
|
+
CANARY_PERCENTAGE: import_zod.z.string().default("0").transform((v) => parseInt(v, 10)).refine((v) => v >= 0 && v <= 100, {
|
|
49
|
+
message: "CANARY_PERCENTAGE must be between 0 and 100"
|
|
50
|
+
}),
|
|
51
|
+
FORCE_LOCAL_EXECUTION: import_zod.z.enum(["true", "false"]).default("false").transform((v) => v === "true"),
|
|
52
|
+
KILL_SWITCH_LOCAL_EXECUTION: import_zod.z.enum(["true", "false"]).default("false").transform((v) => v === "true")
|
|
53
|
+
});
|
|
54
|
+
function parseFeatureFlags(env = process.env) {
|
|
55
|
+
return FeatureFlagsSchema.parse(env);
|
|
56
|
+
}
|
|
57
|
+
function getFeatureFlags() {
|
|
58
|
+
return parseFeatureFlags();
|
|
59
|
+
}
|
|
60
|
+
function isLocalExecutionEnabled(userId, flags = getFeatureFlags()) {
|
|
61
|
+
if (flags.KILL_SWITCH_LOCAL_EXECUTION) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
if (flags.FORCE_LOCAL_EXECUTION) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
if (!flags.LOCAL_EXECUTION_ENABLED) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
if (flags.CANARY_PERCENTAGE >= 100) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
if (flags.CANARY_PERCENTAGE <= 0) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const hash = hashString(userId);
|
|
77
|
+
const userPercentage = hash % 100 + 1;
|
|
78
|
+
return userPercentage <= flags.CANARY_PERCENTAGE;
|
|
79
|
+
}
|
|
80
|
+
function isServerExecutionEnabled(flags = getFeatureFlags()) {
|
|
81
|
+
return flags.SERVER_EXECUTION_ENABLED;
|
|
82
|
+
}
|
|
83
|
+
function validateFlagConfiguration(flags) {
|
|
84
|
+
const errors = [];
|
|
85
|
+
if (flags.FORCE_LOCAL_EXECUTION && flags.KILL_SWITCH_LOCAL_EXECUTION) {
|
|
86
|
+
errors.push("Cannot enable both FORCE_LOCAL_EXECUTION and KILL_SWITCH_LOCAL_EXECUTION");
|
|
87
|
+
}
|
|
88
|
+
if (!flags.LOCAL_EXECUTION_ENABLED && !flags.SERVER_EXECUTION_ENABLED) {
|
|
89
|
+
errors.push("At least one execution mode must be enabled");
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
valid: errors.length === 0,
|
|
93
|
+
errors
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function hashString(str) {
|
|
97
|
+
let hash = 0;
|
|
98
|
+
for (let i = 0; i < str.length; i++) {
|
|
99
|
+
const char = str.charCodeAt(i);
|
|
100
|
+
hash = (hash << 5) - hash + char;
|
|
101
|
+
hash = hash & hash;
|
|
102
|
+
}
|
|
103
|
+
return Math.abs(hash);
|
|
104
|
+
}
|
|
105
|
+
function getMigrationPhase(flags = getFeatureFlags()) {
|
|
106
|
+
if (flags.KILL_SWITCH_LOCAL_EXECUTION) {
|
|
107
|
+
return "rollback";
|
|
108
|
+
}
|
|
109
|
+
if (!flags.SERVER_EXECUTION_ENABLED) {
|
|
110
|
+
return "cutover";
|
|
111
|
+
}
|
|
112
|
+
if (flags.LOCAL_EXECUTION_ENABLED && flags.CANARY_PERCENTAGE > 0) {
|
|
113
|
+
return "canary";
|
|
114
|
+
}
|
|
115
|
+
if (flags.LOCAL_EXECUTION_ENABLED && flags.CANARY_PERCENTAGE === 0) {
|
|
116
|
+
return "shadow";
|
|
117
|
+
}
|
|
118
|
+
return "unknown";
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/validation/security.ts
|
|
122
|
+
var import_zod2 = require("zod");
|
|
123
|
+
var ErrorCategory = import_zod2.z.enum([
|
|
124
|
+
"AUTH",
|
|
125
|
+
"RATE_LIMIT",
|
|
126
|
+
"MERGE_CONFLICT",
|
|
127
|
+
"TIMEOUT",
|
|
128
|
+
"UNKNOWN"
|
|
129
|
+
]);
|
|
130
|
+
var ExecutionStatus = import_zod2.z.enum([
|
|
131
|
+
"pending",
|
|
132
|
+
"running",
|
|
133
|
+
"completed",
|
|
134
|
+
"failed",
|
|
135
|
+
"cancelled"
|
|
136
|
+
]);
|
|
137
|
+
var ExecutionMetadataSyncSchema = import_zod2.z.object({
|
|
138
|
+
taskId: import_zod2.z.string(),
|
|
139
|
+
runId: import_zod2.z.string(),
|
|
140
|
+
status: ExecutionStatus,
|
|
141
|
+
startedAt: import_zod2.z.string().datetime().optional(),
|
|
142
|
+
completedAt: import_zod2.z.string().datetime().optional(),
|
|
143
|
+
durationMs: import_zod2.z.number().int().min(0).optional(),
|
|
144
|
+
progress: import_zod2.z.number().int().min(0).max(100).optional(),
|
|
145
|
+
branch: import_zod2.z.string().optional(),
|
|
146
|
+
commitSha: import_zod2.z.string().optional(),
|
|
147
|
+
prUrl: import_zod2.z.string().url().optional(),
|
|
148
|
+
prNumber: import_zod2.z.number().int().positive().optional(),
|
|
149
|
+
outcome: import_zod2.z.string().max(500).optional(),
|
|
150
|
+
errorCategory: ErrorCategory.optional(),
|
|
151
|
+
filesChanged: import_zod2.z.number().int().min(0).optional(),
|
|
152
|
+
toolsExecuted: import_zod2.z.number().int().min(0).optional()
|
|
153
|
+
}).strict();
|
|
154
|
+
var FORBIDDEN_SYNC_FIELDS = [
|
|
155
|
+
"prompt",
|
|
156
|
+
"logs",
|
|
157
|
+
"toolLogs",
|
|
158
|
+
"executionLogs",
|
|
159
|
+
"repoPath",
|
|
160
|
+
"accessToken",
|
|
161
|
+
"apiKey",
|
|
162
|
+
"passwordHash",
|
|
163
|
+
"jwt",
|
|
164
|
+
"client",
|
|
165
|
+
"timeoutId",
|
|
166
|
+
"rawOutput",
|
|
167
|
+
"diff",
|
|
168
|
+
"fileContents",
|
|
169
|
+
"env",
|
|
170
|
+
"environment",
|
|
171
|
+
"processEnv"
|
|
172
|
+
];
|
|
173
|
+
function isForbiddenField(field) {
|
|
174
|
+
return FORBIDDEN_SYNC_FIELDS.includes(field);
|
|
175
|
+
}
|
|
176
|
+
function sanitizePayload(payload) {
|
|
177
|
+
const sanitized = {};
|
|
178
|
+
const removed = [];
|
|
179
|
+
for (const [key, value] of Object.entries(payload)) {
|
|
180
|
+
if (isForbiddenField(key)) {
|
|
181
|
+
removed.push(key);
|
|
182
|
+
} else {
|
|
183
|
+
sanitized[key] = value;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return { sanitized, removed };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// src/types/execution-metadata.ts
|
|
190
|
+
var import_zod3 = require("zod");
|
|
191
|
+
var ErrorCategory2 = import_zod3.z.enum([
|
|
192
|
+
"AUTH",
|
|
193
|
+
"RATE_LIMIT",
|
|
194
|
+
"MERGE_CONFLICT",
|
|
195
|
+
"TIMEOUT",
|
|
196
|
+
"UNKNOWN"
|
|
197
|
+
]);
|
|
198
|
+
var ExecutionStatus2 = import_zod3.z.enum([
|
|
199
|
+
"pending",
|
|
200
|
+
"running",
|
|
201
|
+
"completed",
|
|
202
|
+
"failed",
|
|
203
|
+
"cancelled"
|
|
204
|
+
]);
|
|
205
|
+
var ExecutionMetadataSyncSchema2 = import_zod3.z.object({
|
|
206
|
+
taskId: import_zod3.z.string(),
|
|
207
|
+
runId: import_zod3.z.string(),
|
|
208
|
+
status: ExecutionStatus2,
|
|
209
|
+
startedAt: import_zod3.z.string().datetime().optional(),
|
|
210
|
+
completedAt: import_zod3.z.string().datetime().optional(),
|
|
211
|
+
durationMs: import_zod3.z.number().int().min(0).optional(),
|
|
212
|
+
progress: import_zod3.z.number().int().min(0).max(100).optional(),
|
|
213
|
+
branch: import_zod3.z.string().optional(),
|
|
214
|
+
commitSha: import_zod3.z.string().optional(),
|
|
215
|
+
prUrl: import_zod3.z.string().url().optional(),
|
|
216
|
+
prNumber: import_zod3.z.number().int().positive().optional(),
|
|
217
|
+
outcome: import_zod3.z.string().max(500).optional(),
|
|
218
|
+
errorCategory: ErrorCategory2.optional(),
|
|
219
|
+
filesChanged: import_zod3.z.number().int().min(0).optional(),
|
|
220
|
+
toolsExecuted: import_zod3.z.number().int().min(0).optional()
|
|
221
|
+
}).strict();
|
|
222
|
+
function validateExecutionMetadataSync(payload) {
|
|
223
|
+
return ExecutionMetadataSyncSchema2.parse(payload);
|
|
224
|
+
}
|
|
225
|
+
function safeValidateExecutionMetadataSync(payload) {
|
|
226
|
+
const result = ExecutionMetadataSyncSchema2.safeParse(payload);
|
|
227
|
+
if (result.success) {
|
|
228
|
+
return { success: true, data: result.data };
|
|
229
|
+
} else {
|
|
230
|
+
return { success: false, error: result.error };
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function checkExecutionMetadataSync(payload) {
|
|
234
|
+
const result = ExecutionMetadataSyncSchema2.safeParse(payload);
|
|
235
|
+
if (result.success) {
|
|
236
|
+
return { valid: true };
|
|
237
|
+
} else {
|
|
238
|
+
return {
|
|
239
|
+
valid: false,
|
|
240
|
+
issues: result.error.errors.map(
|
|
241
|
+
(e) => `${e.path.join(".")}: ${e.message}`
|
|
242
|
+
)
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function validateExecutionMetadataMiddleware() {
|
|
247
|
+
return (req, res, next) => {
|
|
248
|
+
const result = safeValidateExecutionMetadataSync(req.body);
|
|
249
|
+
if (!result.success) {
|
|
250
|
+
const hasUnknownKeys = result.error.errors.some(
|
|
251
|
+
(e) => e.message.includes("Unrecognized key") || e.code === "unrecognized_keys"
|
|
252
|
+
);
|
|
253
|
+
return res.status(400).json({
|
|
254
|
+
error: "Invalid sync payload",
|
|
255
|
+
code: hasUnknownKeys ? "FORBIDDEN_FIELDS" : "VALIDATION_ERROR",
|
|
256
|
+
details: result.error.errors.map((e) => ({
|
|
257
|
+
field: e.path.join("."),
|
|
258
|
+
message: e.message
|
|
259
|
+
}))
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
req.validatedMetadata = result.data;
|
|
263
|
+
next();
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
var FORBIDDEN_SYNC_FIELDS2 = [
|
|
267
|
+
"prompt",
|
|
268
|
+
"logs",
|
|
269
|
+
"toolLogs",
|
|
270
|
+
"executionLogs",
|
|
271
|
+
"repoPath",
|
|
272
|
+
"accessToken",
|
|
273
|
+
"apiKey",
|
|
274
|
+
"passwordHash",
|
|
275
|
+
"jwt",
|
|
276
|
+
"client",
|
|
277
|
+
"timeoutId",
|
|
278
|
+
"rawOutput",
|
|
279
|
+
"diff",
|
|
280
|
+
"fileContents",
|
|
281
|
+
"env",
|
|
282
|
+
"environment",
|
|
283
|
+
"processEnv"
|
|
284
|
+
];
|
|
285
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
286
|
+
0 && (module.exports = {
|
|
287
|
+
ErrorCategory,
|
|
288
|
+
ExecutionMetadataSyncSchema,
|
|
289
|
+
ExecutionStatus,
|
|
290
|
+
FORBIDDEN_SYNC_FIELDS,
|
|
291
|
+
FeatureFlagsSchema,
|
|
292
|
+
checkExecutionMetadataSync,
|
|
293
|
+
getFeatureFlags,
|
|
294
|
+
getMigrationPhase,
|
|
295
|
+
isForbiddenField,
|
|
296
|
+
isLocalExecutionEnabled,
|
|
297
|
+
isServerExecutionEnabled,
|
|
298
|
+
parseFeatureFlags,
|
|
299
|
+
safeValidateExecutionMetadataSync,
|
|
300
|
+
sanitizePayload,
|
|
301
|
+
validateExecutionMetadataMiddleware,
|
|
302
|
+
validateExecutionMetadataSync,
|
|
303
|
+
validateFlagConfiguration
|
|
304
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FeatureFlagsSchema,
|
|
3
|
+
getFeatureFlags,
|
|
4
|
+
getMigrationPhase,
|
|
5
|
+
isLocalExecutionEnabled,
|
|
6
|
+
isServerExecutionEnabled,
|
|
7
|
+
parseFeatureFlags,
|
|
8
|
+
validateFlagConfiguration
|
|
9
|
+
} from "./chunk-5E4TN2YB.mjs";
|
|
10
|
+
import {
|
|
11
|
+
ErrorCategory,
|
|
12
|
+
ExecutionMetadataSyncSchema,
|
|
13
|
+
ExecutionStatus,
|
|
14
|
+
FORBIDDEN_SYNC_FIELDS,
|
|
15
|
+
checkExecutionMetadataSync,
|
|
16
|
+
safeValidateExecutionMetadataSync,
|
|
17
|
+
validateExecutionMetadataMiddleware,
|
|
18
|
+
validateExecutionMetadataSync
|
|
19
|
+
} from "./chunk-HARBMOVK.mjs";
|
|
20
|
+
import {
|
|
21
|
+
isForbiddenField,
|
|
22
|
+
sanitizePayload
|
|
23
|
+
} from "./chunk-P3FFNK6N.mjs";
|
|
24
|
+
export {
|
|
25
|
+
ErrorCategory,
|
|
26
|
+
ExecutionMetadataSyncSchema,
|
|
27
|
+
ExecutionStatus,
|
|
28
|
+
FORBIDDEN_SYNC_FIELDS,
|
|
29
|
+
FeatureFlagsSchema,
|
|
30
|
+
checkExecutionMetadataSync,
|
|
31
|
+
getFeatureFlags,
|
|
32
|
+
getMigrationPhase,
|
|
33
|
+
isForbiddenField,
|
|
34
|
+
isLocalExecutionEnabled,
|
|
35
|
+
isServerExecutionEnabled,
|
|
36
|
+
parseFeatureFlags,
|
|
37
|
+
safeValidateExecutionMetadataSync,
|
|
38
|
+
sanitizePayload,
|
|
39
|
+
validateExecutionMetadataMiddleware,
|
|
40
|
+
validateExecutionMetadataSync,
|
|
41
|
+
validateFlagConfiguration
|
|
42
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const ErrorCategory: z.ZodEnum<["AUTH", "RATE_LIMIT", "MERGE_CONFLICT", "TIMEOUT", "UNKNOWN"]>;
|
|
4
|
+
declare const ExecutionStatus: z.ZodEnum<["pending", "running", "completed", "failed", "cancelled"]>;
|
|
5
|
+
declare const ExecutionMetadataSyncSchema: z.ZodObject<{
|
|
6
|
+
taskId: z.ZodString;
|
|
7
|
+
runId: z.ZodString;
|
|
8
|
+
status: z.ZodEnum<["pending", "running", "completed", "failed", "cancelled"]>;
|
|
9
|
+
startedAt: z.ZodOptional<z.ZodString>;
|
|
10
|
+
completedAt: z.ZodOptional<z.ZodString>;
|
|
11
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
12
|
+
progress: z.ZodOptional<z.ZodNumber>;
|
|
13
|
+
branch: z.ZodOptional<z.ZodString>;
|
|
14
|
+
commitSha: z.ZodOptional<z.ZodString>;
|
|
15
|
+
prUrl: z.ZodOptional<z.ZodString>;
|
|
16
|
+
prNumber: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
outcome: z.ZodOptional<z.ZodString>;
|
|
18
|
+
errorCategory: z.ZodOptional<z.ZodEnum<["AUTH", "RATE_LIMIT", "MERGE_CONFLICT", "TIMEOUT", "UNKNOWN"]>>;
|
|
19
|
+
filesChanged: z.ZodOptional<z.ZodNumber>;
|
|
20
|
+
toolsExecuted: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
}, "strict", z.ZodTypeAny, {
|
|
22
|
+
status: "pending" | "running" | "completed" | "failed" | "cancelled";
|
|
23
|
+
taskId: string;
|
|
24
|
+
runId: string;
|
|
25
|
+
startedAt?: string | undefined;
|
|
26
|
+
completedAt?: string | undefined;
|
|
27
|
+
durationMs?: number | undefined;
|
|
28
|
+
progress?: number | undefined;
|
|
29
|
+
branch?: string | undefined;
|
|
30
|
+
commitSha?: string | undefined;
|
|
31
|
+
prUrl?: string | undefined;
|
|
32
|
+
prNumber?: number | undefined;
|
|
33
|
+
outcome?: string | undefined;
|
|
34
|
+
errorCategory?: "AUTH" | "RATE_LIMIT" | "MERGE_CONFLICT" | "TIMEOUT" | "UNKNOWN" | undefined;
|
|
35
|
+
filesChanged?: number | undefined;
|
|
36
|
+
toolsExecuted?: number | undefined;
|
|
37
|
+
}, {
|
|
38
|
+
status: "pending" | "running" | "completed" | "failed" | "cancelled";
|
|
39
|
+
taskId: string;
|
|
40
|
+
runId: string;
|
|
41
|
+
startedAt?: string | undefined;
|
|
42
|
+
completedAt?: string | undefined;
|
|
43
|
+
durationMs?: number | undefined;
|
|
44
|
+
progress?: number | undefined;
|
|
45
|
+
branch?: string | undefined;
|
|
46
|
+
commitSha?: string | undefined;
|
|
47
|
+
prUrl?: string | undefined;
|
|
48
|
+
prNumber?: number | undefined;
|
|
49
|
+
outcome?: string | undefined;
|
|
50
|
+
errorCategory?: "AUTH" | "RATE_LIMIT" | "MERGE_CONFLICT" | "TIMEOUT" | "UNKNOWN" | undefined;
|
|
51
|
+
filesChanged?: number | undefined;
|
|
52
|
+
toolsExecuted?: number | undefined;
|
|
53
|
+
}>;
|
|
54
|
+
type ExecutionMetadataSync = z.infer<typeof ExecutionMetadataSyncSchema>;
|
|
55
|
+
declare function validateExecutionMetadataSync(payload: unknown): ExecutionMetadataSync;
|
|
56
|
+
declare function safeValidateExecutionMetadataSync(payload: unknown): {
|
|
57
|
+
success: true;
|
|
58
|
+
data: ExecutionMetadataSync;
|
|
59
|
+
} | {
|
|
60
|
+
success: false;
|
|
61
|
+
error: z.ZodError;
|
|
62
|
+
};
|
|
63
|
+
declare function checkExecutionMetadataSync(payload: unknown): {
|
|
64
|
+
valid: boolean;
|
|
65
|
+
issues?: string[];
|
|
66
|
+
};
|
|
67
|
+
declare function validateExecutionMetadataMiddleware(): (req: any, res: any, next: any) => any;
|
|
68
|
+
declare const FORBIDDEN_SYNC_FIELDS: readonly ["prompt", "logs", "toolLogs", "executionLogs", "repoPath", "accessToken", "apiKey", "passwordHash", "jwt", "client", "timeoutId", "rawOutput", "diff", "fileContents", "env", "environment", "processEnv"];
|
|
69
|
+
|
|
70
|
+
export { ErrorCategory, type ExecutionMetadataSync, ExecutionMetadataSyncSchema, ExecutionStatus, FORBIDDEN_SYNC_FIELDS, checkExecutionMetadataSync, safeValidateExecutionMetadataSync, validateExecutionMetadataMiddleware, validateExecutionMetadataSync };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const ErrorCategory: z.ZodEnum<["AUTH", "RATE_LIMIT", "MERGE_CONFLICT", "TIMEOUT", "UNKNOWN"]>;
|
|
4
|
+
declare const ExecutionStatus: z.ZodEnum<["pending", "running", "completed", "failed", "cancelled"]>;
|
|
5
|
+
declare const ExecutionMetadataSyncSchema: z.ZodObject<{
|
|
6
|
+
taskId: z.ZodString;
|
|
7
|
+
runId: z.ZodString;
|
|
8
|
+
status: z.ZodEnum<["pending", "running", "completed", "failed", "cancelled"]>;
|
|
9
|
+
startedAt: z.ZodOptional<z.ZodString>;
|
|
10
|
+
completedAt: z.ZodOptional<z.ZodString>;
|
|
11
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
12
|
+
progress: z.ZodOptional<z.ZodNumber>;
|
|
13
|
+
branch: z.ZodOptional<z.ZodString>;
|
|
14
|
+
commitSha: z.ZodOptional<z.ZodString>;
|
|
15
|
+
prUrl: z.ZodOptional<z.ZodString>;
|
|
16
|
+
prNumber: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
outcome: z.ZodOptional<z.ZodString>;
|
|
18
|
+
errorCategory: z.ZodOptional<z.ZodEnum<["AUTH", "RATE_LIMIT", "MERGE_CONFLICT", "TIMEOUT", "UNKNOWN"]>>;
|
|
19
|
+
filesChanged: z.ZodOptional<z.ZodNumber>;
|
|
20
|
+
toolsExecuted: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
}, "strict", z.ZodTypeAny, {
|
|
22
|
+
status: "pending" | "running" | "completed" | "failed" | "cancelled";
|
|
23
|
+
taskId: string;
|
|
24
|
+
runId: string;
|
|
25
|
+
startedAt?: string | undefined;
|
|
26
|
+
completedAt?: string | undefined;
|
|
27
|
+
durationMs?: number | undefined;
|
|
28
|
+
progress?: number | undefined;
|
|
29
|
+
branch?: string | undefined;
|
|
30
|
+
commitSha?: string | undefined;
|
|
31
|
+
prUrl?: string | undefined;
|
|
32
|
+
prNumber?: number | undefined;
|
|
33
|
+
outcome?: string | undefined;
|
|
34
|
+
errorCategory?: "AUTH" | "RATE_LIMIT" | "MERGE_CONFLICT" | "TIMEOUT" | "UNKNOWN" | undefined;
|
|
35
|
+
filesChanged?: number | undefined;
|
|
36
|
+
toolsExecuted?: number | undefined;
|
|
37
|
+
}, {
|
|
38
|
+
status: "pending" | "running" | "completed" | "failed" | "cancelled";
|
|
39
|
+
taskId: string;
|
|
40
|
+
runId: string;
|
|
41
|
+
startedAt?: string | undefined;
|
|
42
|
+
completedAt?: string | undefined;
|
|
43
|
+
durationMs?: number | undefined;
|
|
44
|
+
progress?: number | undefined;
|
|
45
|
+
branch?: string | undefined;
|
|
46
|
+
commitSha?: string | undefined;
|
|
47
|
+
prUrl?: string | undefined;
|
|
48
|
+
prNumber?: number | undefined;
|
|
49
|
+
outcome?: string | undefined;
|
|
50
|
+
errorCategory?: "AUTH" | "RATE_LIMIT" | "MERGE_CONFLICT" | "TIMEOUT" | "UNKNOWN" | undefined;
|
|
51
|
+
filesChanged?: number | undefined;
|
|
52
|
+
toolsExecuted?: number | undefined;
|
|
53
|
+
}>;
|
|
54
|
+
type ExecutionMetadataSync = z.infer<typeof ExecutionMetadataSyncSchema>;
|
|
55
|
+
declare function validateExecutionMetadataSync(payload: unknown): ExecutionMetadataSync;
|
|
56
|
+
declare function safeValidateExecutionMetadataSync(payload: unknown): {
|
|
57
|
+
success: true;
|
|
58
|
+
data: ExecutionMetadataSync;
|
|
59
|
+
} | {
|
|
60
|
+
success: false;
|
|
61
|
+
error: z.ZodError;
|
|
62
|
+
};
|
|
63
|
+
declare function checkExecutionMetadataSync(payload: unknown): {
|
|
64
|
+
valid: boolean;
|
|
65
|
+
issues?: string[];
|
|
66
|
+
};
|
|
67
|
+
declare function validateExecutionMetadataMiddleware(): (req: any, res: any, next: any) => any;
|
|
68
|
+
declare const FORBIDDEN_SYNC_FIELDS: readonly ["prompt", "logs", "toolLogs", "executionLogs", "repoPath", "accessToken", "apiKey", "passwordHash", "jwt", "client", "timeoutId", "rawOutput", "diff", "fileContents", "env", "environment", "processEnv"];
|
|
69
|
+
|
|
70
|
+
export { ErrorCategory, type ExecutionMetadataSync, ExecutionMetadataSyncSchema, ExecutionStatus, FORBIDDEN_SYNC_FIELDS, checkExecutionMetadataSync, safeValidateExecutionMetadataSync, validateExecutionMetadataMiddleware, validateExecutionMetadataSync };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/types/index.ts
|
|
21
|
+
var types_exports = {};
|
|
22
|
+
__export(types_exports, {
|
|
23
|
+
ErrorCategory: () => ErrorCategory,
|
|
24
|
+
ExecutionMetadataSyncSchema: () => ExecutionMetadataSyncSchema,
|
|
25
|
+
ExecutionStatus: () => ExecutionStatus,
|
|
26
|
+
FORBIDDEN_SYNC_FIELDS: () => FORBIDDEN_SYNC_FIELDS,
|
|
27
|
+
checkExecutionMetadataSync: () => checkExecutionMetadataSync,
|
|
28
|
+
safeValidateExecutionMetadataSync: () => safeValidateExecutionMetadataSync,
|
|
29
|
+
validateExecutionMetadataMiddleware: () => validateExecutionMetadataMiddleware,
|
|
30
|
+
validateExecutionMetadataSync: () => validateExecutionMetadataSync
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(types_exports);
|
|
33
|
+
|
|
34
|
+
// src/types/execution-metadata.ts
|
|
35
|
+
var import_zod = require("zod");
|
|
36
|
+
var ErrorCategory = import_zod.z.enum([
|
|
37
|
+
"AUTH",
|
|
38
|
+
"RATE_LIMIT",
|
|
39
|
+
"MERGE_CONFLICT",
|
|
40
|
+
"TIMEOUT",
|
|
41
|
+
"UNKNOWN"
|
|
42
|
+
]);
|
|
43
|
+
var ExecutionStatus = import_zod.z.enum([
|
|
44
|
+
"pending",
|
|
45
|
+
"running",
|
|
46
|
+
"completed",
|
|
47
|
+
"failed",
|
|
48
|
+
"cancelled"
|
|
49
|
+
]);
|
|
50
|
+
var ExecutionMetadataSyncSchema = import_zod.z.object({
|
|
51
|
+
taskId: import_zod.z.string(),
|
|
52
|
+
runId: import_zod.z.string(),
|
|
53
|
+
status: ExecutionStatus,
|
|
54
|
+
startedAt: import_zod.z.string().datetime().optional(),
|
|
55
|
+
completedAt: import_zod.z.string().datetime().optional(),
|
|
56
|
+
durationMs: import_zod.z.number().int().min(0).optional(),
|
|
57
|
+
progress: import_zod.z.number().int().min(0).max(100).optional(),
|
|
58
|
+
branch: import_zod.z.string().optional(),
|
|
59
|
+
commitSha: import_zod.z.string().optional(),
|
|
60
|
+
prUrl: import_zod.z.string().url().optional(),
|
|
61
|
+
prNumber: import_zod.z.number().int().positive().optional(),
|
|
62
|
+
outcome: import_zod.z.string().max(500).optional(),
|
|
63
|
+
errorCategory: ErrorCategory.optional(),
|
|
64
|
+
filesChanged: import_zod.z.number().int().min(0).optional(),
|
|
65
|
+
toolsExecuted: import_zod.z.number().int().min(0).optional()
|
|
66
|
+
}).strict();
|
|
67
|
+
function validateExecutionMetadataSync(payload) {
|
|
68
|
+
return ExecutionMetadataSyncSchema.parse(payload);
|
|
69
|
+
}
|
|
70
|
+
function safeValidateExecutionMetadataSync(payload) {
|
|
71
|
+
const result = ExecutionMetadataSyncSchema.safeParse(payload);
|
|
72
|
+
if (result.success) {
|
|
73
|
+
return { success: true, data: result.data };
|
|
74
|
+
} else {
|
|
75
|
+
return { success: false, error: result.error };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function checkExecutionMetadataSync(payload) {
|
|
79
|
+
const result = ExecutionMetadataSyncSchema.safeParse(payload);
|
|
80
|
+
if (result.success) {
|
|
81
|
+
return { valid: true };
|
|
82
|
+
} else {
|
|
83
|
+
return {
|
|
84
|
+
valid: false,
|
|
85
|
+
issues: result.error.errors.map(
|
|
86
|
+
(e) => `${e.path.join(".")}: ${e.message}`
|
|
87
|
+
)
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function validateExecutionMetadataMiddleware() {
|
|
92
|
+
return (req, res, next) => {
|
|
93
|
+
const result = safeValidateExecutionMetadataSync(req.body);
|
|
94
|
+
if (!result.success) {
|
|
95
|
+
const hasUnknownKeys = result.error.errors.some(
|
|
96
|
+
(e) => e.message.includes("Unrecognized key") || e.code === "unrecognized_keys"
|
|
97
|
+
);
|
|
98
|
+
return res.status(400).json({
|
|
99
|
+
error: "Invalid sync payload",
|
|
100
|
+
code: hasUnknownKeys ? "FORBIDDEN_FIELDS" : "VALIDATION_ERROR",
|
|
101
|
+
details: result.error.errors.map((e) => ({
|
|
102
|
+
field: e.path.join("."),
|
|
103
|
+
message: e.message
|
|
104
|
+
}))
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
req.validatedMetadata = result.data;
|
|
108
|
+
next();
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
var FORBIDDEN_SYNC_FIELDS = [
|
|
112
|
+
"prompt",
|
|
113
|
+
"logs",
|
|
114
|
+
"toolLogs",
|
|
115
|
+
"executionLogs",
|
|
116
|
+
"repoPath",
|
|
117
|
+
"accessToken",
|
|
118
|
+
"apiKey",
|
|
119
|
+
"passwordHash",
|
|
120
|
+
"jwt",
|
|
121
|
+
"client",
|
|
122
|
+
"timeoutId",
|
|
123
|
+
"rawOutput",
|
|
124
|
+
"diff",
|
|
125
|
+
"fileContents",
|
|
126
|
+
"env",
|
|
127
|
+
"environment",
|
|
128
|
+
"processEnv"
|
|
129
|
+
];
|
|
130
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
131
|
+
0 && (module.exports = {
|
|
132
|
+
ErrorCategory,
|
|
133
|
+
ExecutionMetadataSyncSchema,
|
|
134
|
+
ExecutionStatus,
|
|
135
|
+
FORBIDDEN_SYNC_FIELDS,
|
|
136
|
+
checkExecutionMetadataSync,
|
|
137
|
+
safeValidateExecutionMetadataSync,
|
|
138
|
+
validateExecutionMetadataMiddleware,
|
|
139
|
+
validateExecutionMetadataSync
|
|
140
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ErrorCategory,
|
|
3
|
+
ExecutionMetadataSyncSchema,
|
|
4
|
+
ExecutionStatus,
|
|
5
|
+
FORBIDDEN_SYNC_FIELDS,
|
|
6
|
+
checkExecutionMetadataSync,
|
|
7
|
+
safeValidateExecutionMetadataSync,
|
|
8
|
+
validateExecutionMetadataMiddleware,
|
|
9
|
+
validateExecutionMetadataSync
|
|
10
|
+
} from "../chunk-HARBMOVK.mjs";
|
|
11
|
+
export {
|
|
12
|
+
ErrorCategory,
|
|
13
|
+
ExecutionMetadataSyncSchema,
|
|
14
|
+
ExecutionStatus,
|
|
15
|
+
FORBIDDEN_SYNC_FIELDS,
|
|
16
|
+
checkExecutionMetadataSync,
|
|
17
|
+
safeValidateExecutionMetadataSync,
|
|
18
|
+
validateExecutionMetadataMiddleware,
|
|
19
|
+
validateExecutionMetadataSync
|
|
20
|
+
};
|