@sixb/server 0.1.18 → 0.1.19
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 +3 -3
- package/dist/actions/serialize.d.ts +7 -0
- package/dist/actions/serialize.d.ts.map +1 -0
- package/dist/index.js +660 -685
- package/dist/index.js.map +14 -13
- package/dist/routes/action-runs.d.ts +11 -13
- package/dist/routes/action-runs.d.ts.map +1 -1
- package/dist/routes/actions.d.ts +44 -13
- package/dist/routes/actions.d.ts.map +1 -1
- package/dist/routes/agent-api-gateway.d.ts.map +1 -1
- package/dist/routes/agents.d.ts +20 -20
- package/dist/routes/connector-connection-runs.d.ts +21 -21
- package/dist/routes/connector-connections.d.ts +8 -8
- package/dist/routes/connectors.d.ts +2 -2
- package/dist/routes/datasets.d.ts +5 -5
- package/dist/routes/events.d.ts +4 -4
- package/dist/routes/files.d.ts +15 -12
- package/dist/routes/files.d.ts.map +1 -1
- package/dist/routes/ontology.d.ts +6 -6
- package/dist/routes/pipelines.d.ts +16 -16
- package/dist/routes/projections.d.ts +49 -49
- package/dist/routes/syncs.d.ts +10 -10
- package/dist/routes/webhook-runs.d.ts +2 -2
- package/dist/routes/workflows.d.ts +48 -48
- package/dist/routes/ws/events.d.ts +6 -9
- package/dist/routes/ws/events.d.ts.map +1 -1
- package/dist/schemas/actions.d.ts +100 -84
- package/dist/schemas/actions.d.ts.map +1 -1
- package/dist/schemas/agents.d.ts +20 -20
- package/dist/schemas/ai-limits.d.ts +10 -10
- package/dist/schemas/connectors.d.ts +8 -8
- package/dist/schemas/datasets.d.ts +40 -40
- package/dist/schemas/events.d.ts +24 -24
- package/dist/schemas/events.d.ts.map +1 -1
- package/dist/schemas/files.d.ts +4 -4
- package/dist/schemas/ontology.d.ts +40 -40
- package/dist/schemas/pipelines.d.ts +92 -92
- package/dist/schemas/projections.d.ts +290 -290
- package/dist/schemas/syncs.d.ts +34 -34
- package/dist/schemas/webhook-runs.d.ts +8 -8
- package/dist/schemas/workflows.d.ts +160 -160
- package/dist/server.d.ts +1 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/utils/http.d.ts.map +1 -1
- package/dist/utils/request-body.d.ts +20 -6
- package/dist/utils/request-body.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/actions/serialize.ts +55 -0
- package/src/routes/action-runs.ts +1 -54
- package/src/routes/actions.ts +26 -8
- package/src/routes/agent-api-gateway.ts +18 -42
- package/src/routes/files.ts +15 -63
- package/src/routes/ws/events.ts +2 -12
- package/src/schemas/actions.ts +21 -18
- package/src/server.ts +21 -3
- package/src/utils/http.ts +2 -0
- package/src/utils/request-body.ts +55 -6
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { openapi } from "@elysiajs/openapi";
|
|
|
5
5
|
import { CSRF_HEADER_NAME as CSRF_HEADER_NAME2, setRequestClientAddress } from "@sixb/core/internal/auth";
|
|
6
6
|
import { bindRequestExecution } from "@sixb/core/internal/request-execution";
|
|
7
7
|
import { setApiPublicOrigin } from "@sixb/core/internal/runtime";
|
|
8
|
-
import { Elysia } from "elysia";
|
|
8
|
+
import { Elysia, ParseError } from "elysia";
|
|
9
9
|
import { websocket as elysiaWebSocket } from "elysia/ws";
|
|
10
10
|
import { zodToJsonSchema as zodToJsonSchema2 } from "zod-to-json-schema";
|
|
11
11
|
|
|
@@ -1168,352 +1168,70 @@ var OPENAPI_TAG_METADATA = Object.values(OPENAPI_TAGS).map(({ name, description
|
|
|
1168
1168
|
// src/routes/action-runs.ts
|
|
1169
1169
|
import { z as z5 } from "zod";
|
|
1170
1170
|
|
|
1171
|
-
// src/
|
|
1172
|
-
import {
|
|
1173
|
-
import { fileNameFor } from "@sixb/core";
|
|
1174
|
-
import { BlobStorageError, supportsRangeRead } from "@sixb/core/blob-storage/server";
|
|
1171
|
+
// src/schemas/actions.ts
|
|
1172
|
+
import { SIXB_ERROR_CODES } from "@sixb/core/internal/errors";
|
|
1175
1173
|
import {
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
} from "
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
}
|
|
1190
|
-
};
|
|
1191
|
-
function handleFileContentQueryValidationError(context) {
|
|
1192
|
-
if (context.code !== "VALIDATION" || context.error.type !== "query")
|
|
1193
|
-
return;
|
|
1194
|
-
context.set.status = 400;
|
|
1195
|
-
return { error: "Invalid file content query" };
|
|
1196
|
-
}
|
|
1197
|
-
function fileContentGetResponses(options = {}) {
|
|
1198
|
-
return {
|
|
1199
|
-
200: {
|
|
1200
|
-
description: "File content",
|
|
1201
|
-
content: {
|
|
1202
|
-
"application/octet-stream": {
|
|
1203
|
-
schema: { type: "string", format: "binary" }
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
},
|
|
1207
|
-
206: {
|
|
1208
|
-
description: "Partial file content",
|
|
1209
|
-
content: {
|
|
1210
|
-
"application/octet-stream": {
|
|
1211
|
-
schema: { type: "string", format: "binary" }
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
},
|
|
1215
|
-
304: {
|
|
1216
|
-
description: "File representation is unchanged; reuse the privately cached content"
|
|
1217
|
-
},
|
|
1218
|
-
400: {
|
|
1219
|
-
description: "Response for status 400",
|
|
1220
|
-
content: {
|
|
1221
|
-
"application/json": {
|
|
1222
|
-
schema: { $ref: "#/components/schemas/ErrorResponse" }
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
},
|
|
1226
|
-
404: {
|
|
1227
|
-
description: "Response for status 404",
|
|
1228
|
-
content: {
|
|
1229
|
-
"application/json": {
|
|
1230
|
-
schema: { $ref: "#/components/schemas/ErrorResponse" }
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
},
|
|
1234
|
-
416: {
|
|
1235
|
-
description: "Requested byte range is not satisfiable"
|
|
1236
|
-
},
|
|
1237
|
-
...options.optionalStorage ? unconfiguredStorageResponse : {}
|
|
1238
|
-
};
|
|
1174
|
+
ACTION_RUN_FAILURE_CODES,
|
|
1175
|
+
ACTION_RUN_PHASES
|
|
1176
|
+
} from "@sixb/core/storage";
|
|
1177
|
+
import { z as z3 } from "zod";
|
|
1178
|
+
|
|
1179
|
+
// src/schemas/common.ts
|
|
1180
|
+
import { SIXB_FAILURE_MAX_MESSAGE_BYTES } from "@sixb/core/internal/errors";
|
|
1181
|
+
import { z } from "zod";
|
|
1182
|
+
import { ignoreOverride } from "zod-to-json-schema";
|
|
1183
|
+
var ErrorResponseSchema = z.object({ error: z.string() });
|
|
1184
|
+
function codedErrorResponseSchema(codes) {
|
|
1185
|
+
return ErrorResponseSchema.extend({
|
|
1186
|
+
code: z.enum(codes).describe("Stable machine-readable failure code for programmatic handling.")
|
|
1187
|
+
});
|
|
1239
1188
|
}
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
},
|
|
1267
|
-
416: {
|
|
1268
|
-
description: "Requested byte range is not satisfiable"
|
|
1269
|
-
},
|
|
1270
|
-
...options.optionalStorage ? unconfiguredStorageResponse : {}
|
|
1271
|
-
};
|
|
1189
|
+
var RedactionsSchema = z.record(z.object({ reason: z.literal("missing_clearance") }));
|
|
1190
|
+
var SuccessResponseSchema = z.object({ success: z.boolean() });
|
|
1191
|
+
var PrincipalSchema = z.object({
|
|
1192
|
+
type: z.enum(["user", "serviceAccount", "system"]),
|
|
1193
|
+
id: z.string().min(1)
|
|
1194
|
+
});
|
|
1195
|
+
var JsonValueSchema = z.lazy(() => z.union([
|
|
1196
|
+
z.string(),
|
|
1197
|
+
z.number().finite(),
|
|
1198
|
+
z.boolean(),
|
|
1199
|
+
z.null(),
|
|
1200
|
+
z.array(JsonValueSchema),
|
|
1201
|
+
z.record(JsonValueSchema)
|
|
1202
|
+
]));
|
|
1203
|
+
var JsonNullSchema = JsonValueSchema.refine((value) => value === null);
|
|
1204
|
+
function sixbFailureSchema(codes) {
|
|
1205
|
+
return z.object({
|
|
1206
|
+
code: z.enum(codes),
|
|
1207
|
+
message: z.string().max(SIXB_FAILURE_MAX_MESSAGE_BYTES),
|
|
1208
|
+
retryable: z.boolean(),
|
|
1209
|
+
at: z.string().datetime(),
|
|
1210
|
+
details: JsonValueSchema.optional(),
|
|
1211
|
+
httpStatus: z.number().int().min(100).max(599).optional(),
|
|
1212
|
+
redacted: z.literal(true).optional(),
|
|
1213
|
+
truncated: z.literal(true).optional()
|
|
1214
|
+
});
|
|
1272
1215
|
}
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
}
|
|
1290
|
-
const partialHeaders = partialFileContentHeaders(headers, range, stat.sizeBytes);
|
|
1291
|
-
if (input.head) {
|
|
1292
|
-
return new Response(null, { status: 206, headers: partialHeaders });
|
|
1293
|
-
}
|
|
1294
|
-
try {
|
|
1295
|
-
const stream = await input.blobStorage.openRange(input.fileRef.blobId, range);
|
|
1296
|
-
return new Response(stream, { status: 206, headers: partialHeaders });
|
|
1297
|
-
} catch (error) {
|
|
1298
|
-
if (error instanceof BlobStorageError) {
|
|
1299
|
-
return null;
|
|
1300
|
-
}
|
|
1301
|
-
throw error;
|
|
1302
|
-
}
|
|
1303
|
-
}
|
|
1304
|
-
if (input.head) {
|
|
1305
|
-
return new Response(null, { headers });
|
|
1306
|
-
}
|
|
1307
|
-
try {
|
|
1308
|
-
const stream = await input.blobStorage.open(input.fileRef.blobId);
|
|
1309
|
-
return new Response(stream, { headers });
|
|
1310
|
-
} catch (error) {
|
|
1311
|
-
if (error instanceof BlobStorageError) {
|
|
1312
|
-
return null;
|
|
1313
|
-
}
|
|
1314
|
-
throw error;
|
|
1216
|
+
var JsonValueOpenApiSchema = {
|
|
1217
|
+
description: "Any JSON-compatible value.",
|
|
1218
|
+
nullable: true,
|
|
1219
|
+
anyOf: [
|
|
1220
|
+
{ type: "string" },
|
|
1221
|
+
{ type: "number" },
|
|
1222
|
+
{ type: "boolean" },
|
|
1223
|
+
{ type: "array", items: {} },
|
|
1224
|
+
{ type: "object", additionalProperties: true }
|
|
1225
|
+
]
|
|
1226
|
+
};
|
|
1227
|
+
var jsonValueSchemaDef = JsonValueSchema._def;
|
|
1228
|
+
var jsonNullSchemaDef = JsonNullSchema._def;
|
|
1229
|
+
var jsonValueOpenApiOverride = (def) => {
|
|
1230
|
+
if (def === jsonValueSchemaDef) {
|
|
1231
|
+
return JsonValueOpenApiSchema;
|
|
1315
1232
|
}
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
const missingMessage = input.missingMessage ?? "File not found";
|
|
1319
|
-
const invalidQueryMessage = input.invalidQueryMessage ?? "Invalid file content query";
|
|
1320
|
-
try {
|
|
1321
|
-
const parsed = input.querySchema.parse(input.query);
|
|
1322
|
-
const root = await input.resolveRoot(parsed);
|
|
1323
|
-
if (root === null || root === undefined) {
|
|
1324
|
-
return fileContentNotFound(input.set, missingMessage);
|
|
1325
|
-
}
|
|
1326
|
-
const fileRef = resolveFileRefAtPath(root, parsed.path);
|
|
1327
|
-
if (!fileRef) {
|
|
1328
|
-
return fileContentNotFound(input.set, missingMessage);
|
|
1329
|
-
}
|
|
1330
|
-
const response = await createFileContentResponse({
|
|
1331
|
-
blobStorage: input.blobStorage,
|
|
1332
|
-
fileRef,
|
|
1333
|
-
disposition: parsed.disposition,
|
|
1334
|
-
head: input.head,
|
|
1335
|
-
rangeHeader: input.request.headers.get("range"),
|
|
1336
|
-
ifNoneMatchHeader: input.request.headers.get("if-none-match"),
|
|
1337
|
-
ifRangeHeader: input.request.headers.get("if-range")
|
|
1338
|
-
});
|
|
1339
|
-
if (!response) {
|
|
1340
|
-
return fileContentNotFound(input.set, missingMessage);
|
|
1341
|
-
}
|
|
1342
|
-
return response;
|
|
1343
|
-
} catch (error) {
|
|
1344
|
-
if (error instanceof ZodError) {
|
|
1345
|
-
input.set.status = 400;
|
|
1346
|
-
return { error: invalidQueryMessage };
|
|
1347
|
-
}
|
|
1348
|
-
if (input.hideError?.(error)) {
|
|
1349
|
-
return fileContentNotFound(input.set, missingMessage);
|
|
1350
|
-
}
|
|
1351
|
-
throw error;
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
function fileContentNotFound(set, message) {
|
|
1355
|
-
set.status = 404;
|
|
1356
|
-
return { error: message };
|
|
1357
|
-
}
|
|
1358
|
-
function matchesIfNoneMatch(header, etag) {
|
|
1359
|
-
return header?.trim() === "*" || (header?.split(",").some((value) => value.trim().replace(/^W\//, "") === etag) ?? false);
|
|
1360
|
-
}
|
|
1361
|
-
var INLINE_MEDIA_TYPES = new Set([
|
|
1362
|
-
"application/json",
|
|
1363
|
-
"application/pdf",
|
|
1364
|
-
"image/avif",
|
|
1365
|
-
"image/bmp",
|
|
1366
|
-
"image/gif",
|
|
1367
|
-
"image/jpeg",
|
|
1368
|
-
"image/png",
|
|
1369
|
-
"image/webp",
|
|
1370
|
-
"text/markdown",
|
|
1371
|
-
"text/plain"
|
|
1372
|
-
]);
|
|
1373
|
-
var FILE_CONTENT_SECURITY_POLICY = "default-src 'none'; style-src 'unsafe-inline'; sandbox";
|
|
1374
|
-
var PDF_CONTENT_SECURITY_POLICY = "default-src 'none'; style-src 'unsafe-inline'; object-src 'self'";
|
|
1375
|
-
function fileContentHeaders(fileRef, stat, requestedDisposition, canReadRange) {
|
|
1376
|
-
const mediaType = canonicalMediaType(fileRef.mediaType) ?? "application/octet-stream";
|
|
1377
|
-
const baseType = mediaType.split(";", 1)[0];
|
|
1378
|
-
const disposition = (requestedDisposition ?? "inline") === "inline" && INLINE_MEDIA_TYPES.has(baseType) ? "inline" : "attachment";
|
|
1379
|
-
const headers = new Headers;
|
|
1380
|
-
headers.set("content-type", mediaType);
|
|
1381
|
-
headers.set("content-length", stat.sizeBytes.toString());
|
|
1382
|
-
headers.set("content-disposition", contentDispositionHeader(disposition, fileNameFor(fileRef)));
|
|
1383
|
-
headers.set("content-security-policy", baseType === "application/pdf" ? PDF_CONTENT_SECURITY_POLICY : FILE_CONTENT_SECURITY_POLICY);
|
|
1384
|
-
const representation = JSON.stringify([
|
|
1385
|
-
fileRef.digest,
|
|
1386
|
-
mediaType,
|
|
1387
|
-
headers.get("content-disposition")
|
|
1388
|
-
]);
|
|
1389
|
-
headers.set("etag", `"sha256:${createHash2("sha256").update(representation).digest("hex")}"`);
|
|
1390
|
-
headers.set("x-content-type-options", "nosniff");
|
|
1391
|
-
headers.set("cache-control", "private, no-cache");
|
|
1392
|
-
if (canReadRange) {
|
|
1393
|
-
headers.set("accept-ranges", "bytes");
|
|
1394
|
-
}
|
|
1395
|
-
return headers;
|
|
1396
|
-
}
|
|
1397
|
-
function parseSingleByteRange(header, sizeBytes) {
|
|
1398
|
-
const normalized = header.trim();
|
|
1399
|
-
if (!normalized.startsWith("bytes=") || normalized.includes(",")) {
|
|
1400
|
-
return null;
|
|
1401
|
-
}
|
|
1402
|
-
if (sizeBytes <= 0) {
|
|
1403
|
-
return null;
|
|
1404
|
-
}
|
|
1405
|
-
const spec = normalized.slice("bytes=".length).trim();
|
|
1406
|
-
const match = spec.match(/^(\d*)-(\d*)$/);
|
|
1407
|
-
if (!match) {
|
|
1408
|
-
return null;
|
|
1409
|
-
}
|
|
1410
|
-
const [, rawStart, rawEnd] = match;
|
|
1411
|
-
if (!rawStart && !rawEnd) {
|
|
1412
|
-
return null;
|
|
1413
|
-
}
|
|
1414
|
-
if (!rawStart) {
|
|
1415
|
-
const suffixLength = Number(rawEnd);
|
|
1416
|
-
if (!Number.isSafeInteger(suffixLength) || suffixLength <= 0) {
|
|
1417
|
-
return null;
|
|
1418
|
-
}
|
|
1419
|
-
return {
|
|
1420
|
-
start: Math.max(sizeBytes - suffixLength, 0),
|
|
1421
|
-
endInclusive: sizeBytes - 1
|
|
1422
|
-
};
|
|
1423
|
-
}
|
|
1424
|
-
const start = Number(rawStart);
|
|
1425
|
-
if (!Number.isSafeInteger(start) || start >= sizeBytes) {
|
|
1426
|
-
return null;
|
|
1427
|
-
}
|
|
1428
|
-
const requestedEnd = rawEnd ? Number(rawEnd) : sizeBytes - 1;
|
|
1429
|
-
if (!Number.isSafeInteger(requestedEnd) || requestedEnd < start) {
|
|
1430
|
-
return null;
|
|
1431
|
-
}
|
|
1432
|
-
return {
|
|
1433
|
-
start,
|
|
1434
|
-
endInclusive: Math.min(requestedEnd, sizeBytes - 1)
|
|
1435
|
-
};
|
|
1436
|
-
}
|
|
1437
|
-
function partialFileContentHeaders(baseHeaders, range, sizeBytes) {
|
|
1438
|
-
const headers = new Headers(baseHeaders);
|
|
1439
|
-
headers.set("content-length", (range.endInclusive - range.start + 1).toString());
|
|
1440
|
-
headers.set("content-range", `bytes ${range.start}-${range.endInclusive}/${sizeBytes}`);
|
|
1441
|
-
return headers;
|
|
1442
|
-
}
|
|
1443
|
-
function rangeNotSatisfiableResponse(sizeBytes) {
|
|
1444
|
-
const headers = new Headers;
|
|
1445
|
-
headers.set("accept-ranges", "bytes");
|
|
1446
|
-
headers.set("content-range", `bytes */${sizeBytes}`);
|
|
1447
|
-
return new Response(null, { status: 416, headers });
|
|
1448
|
-
}
|
|
1449
|
-
function contentDispositionHeader(disposition, fileName) {
|
|
1450
|
-
const asciiFileName = fileName.replace(/[^\x20-\x7e]/g, "_").replaceAll('"', "'");
|
|
1451
|
-
return `${disposition}; filename="${asciiFileName}"; filename*=UTF-8''${encodeURIComponent(fileName)}`;
|
|
1452
|
-
}
|
|
1453
|
-
|
|
1454
|
-
// src/schemas/actions.ts
|
|
1455
|
-
import {
|
|
1456
|
-
ACTION_RUN_FAILURE_CODES,
|
|
1457
|
-
ACTION_RUN_PHASES
|
|
1458
|
-
} from "@sixb/core/storage";
|
|
1459
|
-
import { z as z3 } from "zod";
|
|
1460
|
-
|
|
1461
|
-
// src/schemas/common.ts
|
|
1462
|
-
import { SIXB_FAILURE_MAX_MESSAGE_BYTES } from "@sixb/core/internal/errors";
|
|
1463
|
-
import { z } from "zod";
|
|
1464
|
-
import { ignoreOverride } from "zod-to-json-schema";
|
|
1465
|
-
var ErrorResponseSchema = z.object({ error: z.string() });
|
|
1466
|
-
function codedErrorResponseSchema(codes) {
|
|
1467
|
-
return ErrorResponseSchema.extend({
|
|
1468
|
-
code: z.enum(codes).describe("Stable machine-readable failure code for programmatic handling.")
|
|
1469
|
-
});
|
|
1470
|
-
}
|
|
1471
|
-
var RedactionsSchema = z.record(z.object({ reason: z.literal("missing_clearance") }));
|
|
1472
|
-
var SuccessResponseSchema = z.object({ success: z.boolean() });
|
|
1473
|
-
var PrincipalSchema = z.object({
|
|
1474
|
-
type: z.enum(["user", "serviceAccount", "system"]),
|
|
1475
|
-
id: z.string().min(1)
|
|
1476
|
-
});
|
|
1477
|
-
var JsonValueSchema = z.lazy(() => z.union([
|
|
1478
|
-
z.string(),
|
|
1479
|
-
z.number().finite(),
|
|
1480
|
-
z.boolean(),
|
|
1481
|
-
z.null(),
|
|
1482
|
-
z.array(JsonValueSchema),
|
|
1483
|
-
z.record(JsonValueSchema)
|
|
1484
|
-
]));
|
|
1485
|
-
var JsonNullSchema = JsonValueSchema.refine((value) => value === null);
|
|
1486
|
-
function sixbFailureSchema(codes) {
|
|
1487
|
-
return z.object({
|
|
1488
|
-
code: z.enum(codes),
|
|
1489
|
-
message: z.string().max(SIXB_FAILURE_MAX_MESSAGE_BYTES),
|
|
1490
|
-
retryable: z.boolean(),
|
|
1491
|
-
at: z.string().datetime(),
|
|
1492
|
-
details: JsonValueSchema.optional(),
|
|
1493
|
-
httpStatus: z.number().int().min(100).max(599).optional(),
|
|
1494
|
-
redacted: z.literal(true).optional(),
|
|
1495
|
-
truncated: z.literal(true).optional()
|
|
1496
|
-
});
|
|
1497
|
-
}
|
|
1498
|
-
var JsonValueOpenApiSchema = {
|
|
1499
|
-
description: "Any JSON-compatible value.",
|
|
1500
|
-
nullable: true,
|
|
1501
|
-
anyOf: [
|
|
1502
|
-
{ type: "string" },
|
|
1503
|
-
{ type: "number" },
|
|
1504
|
-
{ type: "boolean" },
|
|
1505
|
-
{ type: "array", items: {} },
|
|
1506
|
-
{ type: "object", additionalProperties: true }
|
|
1507
|
-
]
|
|
1508
|
-
};
|
|
1509
|
-
var jsonValueSchemaDef = JsonValueSchema._def;
|
|
1510
|
-
var jsonNullSchemaDef = JsonNullSchema._def;
|
|
1511
|
-
var jsonValueOpenApiOverride = (def) => {
|
|
1512
|
-
if (def === jsonValueSchemaDef) {
|
|
1513
|
-
return JsonValueOpenApiSchema;
|
|
1514
|
-
}
|
|
1515
|
-
if (def === jsonNullSchemaDef) {
|
|
1516
|
-
return { nullable: true, enum: [null] };
|
|
1233
|
+
if (def === jsonNullSchemaDef) {
|
|
1234
|
+
return { nullable: true, enum: [null] };
|
|
1517
1235
|
}
|
|
1518
1236
|
return ignoreOverride;
|
|
1519
1237
|
};
|
|
@@ -1625,12 +1343,11 @@ var RequestActionBodySchema = z3.object({
|
|
|
1625
1343
|
params: z3.record(z3.unknown()).optional(),
|
|
1626
1344
|
runId: z3.string().min(1).optional()
|
|
1627
1345
|
});
|
|
1628
|
-
var
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
});
|
|
1346
|
+
var ActionRunInProgressResponseSchema = codedErrorResponseSchema([
|
|
1347
|
+
"action.run_in_progress"
|
|
1348
|
+
]);
|
|
1349
|
+
var ActionRequestFailedResponseSchema = codedErrorResponseSchema(SIXB_ERROR_CODES);
|
|
1350
|
+
var RuntimeStoppingResponseSchema = codedErrorResponseSchema(["runtime.stopping"]);
|
|
1634
1351
|
var ActionCatalogItemSchema = z3.object({
|
|
1635
1352
|
id: z3.string(),
|
|
1636
1353
|
name: z3.string(),
|
|
@@ -1647,13 +1364,7 @@ var ActionCatalogItemSchema = z3.object({
|
|
|
1647
1364
|
var ActionDetailSchema = ActionCatalogItemSchema.extend({
|
|
1648
1365
|
inputSchema: z3.record(z3.unknown())
|
|
1649
1366
|
});
|
|
1650
|
-
var ActionRunStatusSchema = z3.enum([
|
|
1651
|
-
"queued",
|
|
1652
|
-
"running",
|
|
1653
|
-
"succeeded",
|
|
1654
|
-
"failed",
|
|
1655
|
-
"cancelled"
|
|
1656
|
-
]);
|
|
1367
|
+
var ActionRunStatusSchema = z3.enum(["succeeded", "failed"]);
|
|
1657
1368
|
var ActionRunPhaseSchema = z3.enum(ACTION_RUN_PHASES);
|
|
1658
1369
|
var ActionRunsQuerySchema = z3.object({
|
|
1659
1370
|
actionId: z3.string().optional(),
|
|
@@ -1693,10 +1404,9 @@ var ActionRunSummarySchema = z3.object({
|
|
|
1693
1404
|
actionId: z3.string(),
|
|
1694
1405
|
subject: ActionSubjectSchema,
|
|
1695
1406
|
status: ActionRunStatusSchema,
|
|
1696
|
-
phase: ActionRunPhaseSchema
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
finishedAt: z3.string().optional(),
|
|
1407
|
+
phase: ActionRunPhaseSchema,
|
|
1408
|
+
startedAt: z3.string(),
|
|
1409
|
+
finishedAt: z3.string(),
|
|
1700
1410
|
error: ActionRunFailureSchema.optional()
|
|
1701
1411
|
});
|
|
1702
1412
|
var ActionRunWritebackRecordSchema = z3.discriminatedUnion("status", [
|
|
@@ -1733,6 +1443,520 @@ var ActionRunListResponseSchema = z3.object({
|
|
|
1733
1443
|
total: z3.number()
|
|
1734
1444
|
});
|
|
1735
1445
|
|
|
1446
|
+
// src/utils/http.ts
|
|
1447
|
+
import {
|
|
1448
|
+
AuthorizationError,
|
|
1449
|
+
OntologyNotFoundError,
|
|
1450
|
+
OntologyValidationError
|
|
1451
|
+
} from "@sixb/core";
|
|
1452
|
+
import { isSixbError } from "@sixb/core/internal/errors";
|
|
1453
|
+
import {
|
|
1454
|
+
FileUploadSessionError,
|
|
1455
|
+
ObjectNotFoundError
|
|
1456
|
+
} from "@sixb/core/storage";
|
|
1457
|
+
|
|
1458
|
+
// src/utils/request-body.ts
|
|
1459
|
+
var DEFAULT_REQUEST_BODY_LIMIT_BYTES = 1024 * 1024;
|
|
1460
|
+
|
|
1461
|
+
class RequestBodyTooLargeError extends Error {
|
|
1462
|
+
limitBytes;
|
|
1463
|
+
name = "RequestBodyTooLargeError";
|
|
1464
|
+
constructor(limitBytes, message = `Request body exceeds the ${limitBytes} byte limit.`) {
|
|
1465
|
+
super(message);
|
|
1466
|
+
this.limitBytes = limitBytes;
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
var requestBodyCaps = new WeakMap;
|
|
1470
|
+
function limitRequestBody(request) {
|
|
1471
|
+
if (!request.body) {
|
|
1472
|
+
return request;
|
|
1473
|
+
}
|
|
1474
|
+
const cap = { lifted: false };
|
|
1475
|
+
let total = 0;
|
|
1476
|
+
const body = request.body.pipeThrough(new TransformStream({
|
|
1477
|
+
transform(chunk, controller) {
|
|
1478
|
+
total += chunk.byteLength;
|
|
1479
|
+
if (!cap.lifted && total > DEFAULT_REQUEST_BODY_LIMIT_BYTES) {
|
|
1480
|
+
controller.error(new RequestBodyTooLargeError(DEFAULT_REQUEST_BODY_LIMIT_BYTES));
|
|
1481
|
+
return;
|
|
1482
|
+
}
|
|
1483
|
+
controller.enqueue(chunk);
|
|
1484
|
+
}
|
|
1485
|
+
}));
|
|
1486
|
+
const limited = new Request(request, { body, duplex: "half" });
|
|
1487
|
+
requestBodyCaps.set(limited, cap);
|
|
1488
|
+
return limited;
|
|
1489
|
+
}
|
|
1490
|
+
async function readRequestBodyWithLimit(request, limitBytes, tooLargeMessage) {
|
|
1491
|
+
const cap = requestBodyCaps.get(request);
|
|
1492
|
+
if (cap) {
|
|
1493
|
+
cap.lifted = true;
|
|
1494
|
+
}
|
|
1495
|
+
const contentLength = request.headers.get("content-length");
|
|
1496
|
+
if (contentLength !== null) {
|
|
1497
|
+
const declared = Number(contentLength);
|
|
1498
|
+
if (Number.isSafeInteger(declared) && declared > limitBytes) {
|
|
1499
|
+
throw new RequestBodyTooLargeError(limitBytes, tooLargeMessage);
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
if (!request.body) {
|
|
1503
|
+
return new Uint8Array(0);
|
|
1504
|
+
}
|
|
1505
|
+
const reader = request.body.getReader();
|
|
1506
|
+
const chunks = [];
|
|
1507
|
+
let total = 0;
|
|
1508
|
+
while (true) {
|
|
1509
|
+
const { done, value } = await reader.read();
|
|
1510
|
+
if (done) {
|
|
1511
|
+
break;
|
|
1512
|
+
}
|
|
1513
|
+
total += value.byteLength;
|
|
1514
|
+
if (total > limitBytes) {
|
|
1515
|
+
await reader.cancel();
|
|
1516
|
+
throw new RequestBodyTooLargeError(limitBytes, tooLargeMessage);
|
|
1517
|
+
}
|
|
1518
|
+
chunks.push(value);
|
|
1519
|
+
}
|
|
1520
|
+
const result = new Uint8Array(total);
|
|
1521
|
+
let offset = 0;
|
|
1522
|
+
for (const chunk of chunks) {
|
|
1523
|
+
result.set(chunk, offset);
|
|
1524
|
+
offset += chunk.byteLength;
|
|
1525
|
+
}
|
|
1526
|
+
return result;
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
// src/utils/http.ts
|
|
1530
|
+
var HTTP_STATUS_BY_ERROR_CODE = {
|
|
1531
|
+
"action.run_in_progress": 409,
|
|
1532
|
+
"connector.adapter_invalid": 502,
|
|
1533
|
+
"connector.authorization_invalid": 400,
|
|
1534
|
+
"connector.authorization_required": 409,
|
|
1535
|
+
"connector.configuration_invalid": 400,
|
|
1536
|
+
"connector.credentials_unavailable": 503,
|
|
1537
|
+
"connector.not_found": 404,
|
|
1538
|
+
"connector.operation_conflict": 409,
|
|
1539
|
+
"connector.operation_in_progress": 409,
|
|
1540
|
+
"connector.provider_failed": 502,
|
|
1541
|
+
"connector.provider_unavailable": 503,
|
|
1542
|
+
"connector.replacement_required": 409,
|
|
1543
|
+
"connector.revocation_pending": 409,
|
|
1544
|
+
"dataset.not_found": 404,
|
|
1545
|
+
"dataset.version_not_found": 404,
|
|
1546
|
+
"runtime.stopping": 503,
|
|
1547
|
+
"ai.usage_limit_exceeded": 429,
|
|
1548
|
+
"ai.usage_limit_unavailable": 429
|
|
1549
|
+
};
|
|
1550
|
+
function toIsoString(value) {
|
|
1551
|
+
return value.toISOString();
|
|
1552
|
+
}
|
|
1553
|
+
function parseDate(value) {
|
|
1554
|
+
if (!value) {
|
|
1555
|
+
return;
|
|
1556
|
+
}
|
|
1557
|
+
const parsed = new Date(value);
|
|
1558
|
+
if (Number.isNaN(parsed.getTime())) {
|
|
1559
|
+
throw new Error(`Invalid date: ${value}`);
|
|
1560
|
+
}
|
|
1561
|
+
return parsed;
|
|
1562
|
+
}
|
|
1563
|
+
function parseOptionalInt(value) {
|
|
1564
|
+
if (value === undefined) {
|
|
1565
|
+
return;
|
|
1566
|
+
}
|
|
1567
|
+
const parsed = Number.parseInt(value, 10);
|
|
1568
|
+
if (!Number.isFinite(parsed)) {
|
|
1569
|
+
throw new Error(`Invalid integer: ${value}`);
|
|
1570
|
+
}
|
|
1571
|
+
return parsed;
|
|
1572
|
+
}
|
|
1573
|
+
function unconfiguredStorageResponse(set, role) {
|
|
1574
|
+
set.status = 501;
|
|
1575
|
+
return { error: `[SixbServer] ${role} is not configured on this runtime.` };
|
|
1576
|
+
}
|
|
1577
|
+
function handleRouteError(error, set) {
|
|
1578
|
+
if (isSixbError(error)) {
|
|
1579
|
+
set.status = HTTP_STATUS_BY_ERROR_CODE[error.code] ?? 500;
|
|
1580
|
+
if (error.code === "ai.usage_limit_exceeded")
|
|
1581
|
+
setRetryAfterFromDetails(set, error.details);
|
|
1582
|
+
const exposesDetails = error.code === "ai.usage_limit_exceeded" || error.code === "ai.usage_limit_unavailable";
|
|
1583
|
+
return {
|
|
1584
|
+
error: error.message,
|
|
1585
|
+
code: error.code,
|
|
1586
|
+
...!exposesDetails || error.details === undefined ? {} : { details: error.details }
|
|
1587
|
+
};
|
|
1588
|
+
}
|
|
1589
|
+
if (error instanceof AuthorizationError) {
|
|
1590
|
+
set.status = 403;
|
|
1591
|
+
return { error: error.message };
|
|
1592
|
+
}
|
|
1593
|
+
if (error instanceof FileUploadSessionError) {
|
|
1594
|
+
set.status = fileUploadSessionErrorStatus(error.reason);
|
|
1595
|
+
return { error: error.message };
|
|
1596
|
+
}
|
|
1597
|
+
if (error instanceof RequestBodyTooLargeError) {
|
|
1598
|
+
set.status = 413;
|
|
1599
|
+
return { error: error.message };
|
|
1600
|
+
}
|
|
1601
|
+
if (error instanceof OntologyNotFoundError || error instanceof ObjectNotFoundError) {
|
|
1602
|
+
set.status = 404;
|
|
1603
|
+
return { error: error.message };
|
|
1604
|
+
}
|
|
1605
|
+
if (error instanceof OntologyValidationError) {
|
|
1606
|
+
set.status = 400;
|
|
1607
|
+
return { error: error.message };
|
|
1608
|
+
}
|
|
1609
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1610
|
+
set.status = 400;
|
|
1611
|
+
return { error: message };
|
|
1612
|
+
}
|
|
1613
|
+
function setRetryAfterFromDetails(set, details) {
|
|
1614
|
+
if (typeof details !== "object" || details === null || Array.isArray(details))
|
|
1615
|
+
return;
|
|
1616
|
+
const resetAt = details.resetAt;
|
|
1617
|
+
if (typeof resetAt !== "string")
|
|
1618
|
+
return;
|
|
1619
|
+
const resetTime = Date.parse(resetAt);
|
|
1620
|
+
if (!Number.isFinite(resetTime))
|
|
1621
|
+
return;
|
|
1622
|
+
const seconds = String(Math.max(0, Math.ceil((resetTime - Date.now()) / 1000)));
|
|
1623
|
+
const headers = typeof set.headers === "object" && set.headers !== null ? set.headers : {};
|
|
1624
|
+
headers["Retry-After"] = seconds;
|
|
1625
|
+
set.headers = headers;
|
|
1626
|
+
}
|
|
1627
|
+
function fileUploadSessionErrorStatus(reason) {
|
|
1628
|
+
switch (reason) {
|
|
1629
|
+
case "not_found":
|
|
1630
|
+
return 404;
|
|
1631
|
+
case "expired":
|
|
1632
|
+
return 410;
|
|
1633
|
+
case "already_completed":
|
|
1634
|
+
case "already_aborted":
|
|
1635
|
+
return 409;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
// src/actions/serialize.ts
|
|
1640
|
+
function serializeActionRunSummary(run) {
|
|
1641
|
+
return ActionRunSummarySchema.parse({
|
|
1642
|
+
id: run.id,
|
|
1643
|
+
projectId: run.projectId,
|
|
1644
|
+
actionId: run.actionId,
|
|
1645
|
+
subject: run.subject,
|
|
1646
|
+
status: run.status,
|
|
1647
|
+
phase: run.phase,
|
|
1648
|
+
startedAt: toIsoString(run.startedAt),
|
|
1649
|
+
finishedAt: toIsoString(run.finishedAt),
|
|
1650
|
+
error: run.error
|
|
1651
|
+
});
|
|
1652
|
+
}
|
|
1653
|
+
function serializeActionRunDetail(run) {
|
|
1654
|
+
return ActionRunDetailSchema.parse({
|
|
1655
|
+
...serializeActionRunSummary(run),
|
|
1656
|
+
params: run.params,
|
|
1657
|
+
writeback: run.writeback ? run.writeback.status === "succeeded" ? {
|
|
1658
|
+
status: "succeeded",
|
|
1659
|
+
completedAt: toIsoString(run.writeback.completedAt),
|
|
1660
|
+
result: run.writeback.result
|
|
1661
|
+
} : {
|
|
1662
|
+
status: "failed",
|
|
1663
|
+
completedAt: toIsoString(run.writeback.completedAt),
|
|
1664
|
+
error: run.writeback.error
|
|
1665
|
+
} : undefined,
|
|
1666
|
+
effects: run.effects ? run.effects.status === "succeeded" ? {
|
|
1667
|
+
status: "succeeded",
|
|
1668
|
+
completedAt: toIsoString(run.effects.completedAt)
|
|
1669
|
+
} : {
|
|
1670
|
+
status: "failed",
|
|
1671
|
+
completedAt: toIsoString(run.effects.completedAt),
|
|
1672
|
+
error: run.effects.error
|
|
1673
|
+
} : undefined
|
|
1674
|
+
});
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
// src/files/content.ts
|
|
1678
|
+
import { createHash as createHash2 } from "crypto";
|
|
1679
|
+
import { fileNameFor } from "@sixb/core";
|
|
1680
|
+
import { BlobStorageError, supportsRangeRead } from "@sixb/core/blob-storage/server";
|
|
1681
|
+
import {
|
|
1682
|
+
canonicalMediaType,
|
|
1683
|
+
resolveFileRefAtPath,
|
|
1684
|
+
statFileRef
|
|
1685
|
+
} from "@sixb/core/internal/blob-storage";
|
|
1686
|
+
import { ZodError } from "zod";
|
|
1687
|
+
var unconfiguredStorageResponse2 = {
|
|
1688
|
+
501: {
|
|
1689
|
+
description: "The storage role backing this content is not configured",
|
|
1690
|
+
content: {
|
|
1691
|
+
"application/json": {
|
|
1692
|
+
schema: { $ref: "#/components/schemas/ErrorResponse" }
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
};
|
|
1697
|
+
function handleFileContentQueryValidationError(context) {
|
|
1698
|
+
if (context.code !== "VALIDATION" || context.error.type !== "query")
|
|
1699
|
+
return;
|
|
1700
|
+
context.set.status = 400;
|
|
1701
|
+
return { error: "Invalid file content query" };
|
|
1702
|
+
}
|
|
1703
|
+
function fileContentGetResponses(options = {}) {
|
|
1704
|
+
return {
|
|
1705
|
+
200: {
|
|
1706
|
+
description: "File content",
|
|
1707
|
+
content: {
|
|
1708
|
+
"application/octet-stream": {
|
|
1709
|
+
schema: { type: "string", format: "binary" }
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
},
|
|
1713
|
+
206: {
|
|
1714
|
+
description: "Partial file content",
|
|
1715
|
+
content: {
|
|
1716
|
+
"application/octet-stream": {
|
|
1717
|
+
schema: { type: "string", format: "binary" }
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
},
|
|
1721
|
+
304: {
|
|
1722
|
+
description: "File representation is unchanged; reuse the privately cached content"
|
|
1723
|
+
},
|
|
1724
|
+
400: {
|
|
1725
|
+
description: "Response for status 400",
|
|
1726
|
+
content: {
|
|
1727
|
+
"application/json": {
|
|
1728
|
+
schema: { $ref: "#/components/schemas/ErrorResponse" }
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
},
|
|
1732
|
+
404: {
|
|
1733
|
+
description: "Response for status 404",
|
|
1734
|
+
content: {
|
|
1735
|
+
"application/json": {
|
|
1736
|
+
schema: { $ref: "#/components/schemas/ErrorResponse" }
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
},
|
|
1740
|
+
416: {
|
|
1741
|
+
description: "Requested byte range is not satisfiable"
|
|
1742
|
+
},
|
|
1743
|
+
...options.optionalStorage ? unconfiguredStorageResponse2 : {}
|
|
1744
|
+
};
|
|
1745
|
+
}
|
|
1746
|
+
function fileContentHeadResponses(options = {}) {
|
|
1747
|
+
return {
|
|
1748
|
+
200: {
|
|
1749
|
+
description: "File content headers"
|
|
1750
|
+
},
|
|
1751
|
+
206: {
|
|
1752
|
+
description: "Partial file content headers"
|
|
1753
|
+
},
|
|
1754
|
+
304: {
|
|
1755
|
+
description: "File representation is unchanged; reuse the privately cached content"
|
|
1756
|
+
},
|
|
1757
|
+
400: {
|
|
1758
|
+
description: "Response for status 400",
|
|
1759
|
+
content: {
|
|
1760
|
+
"application/json": {
|
|
1761
|
+
schema: { $ref: "#/components/schemas/ErrorResponse" }
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
},
|
|
1765
|
+
404: {
|
|
1766
|
+
description: "Response for status 404",
|
|
1767
|
+
content: {
|
|
1768
|
+
"application/json": {
|
|
1769
|
+
schema: { $ref: "#/components/schemas/ErrorResponse" }
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
},
|
|
1773
|
+
416: {
|
|
1774
|
+
description: "Requested byte range is not satisfiable"
|
|
1775
|
+
},
|
|
1776
|
+
...options.optionalStorage ? unconfiguredStorageResponse2 : {}
|
|
1777
|
+
};
|
|
1778
|
+
}
|
|
1779
|
+
async function createFileContentResponse(input) {
|
|
1780
|
+
const stat = await statFileRef(input.blobStorage, input.fileRef);
|
|
1781
|
+
if (!stat) {
|
|
1782
|
+
return null;
|
|
1783
|
+
}
|
|
1784
|
+
const canReadRange = supportsRangeRead(input.blobStorage);
|
|
1785
|
+
const headers = fileContentHeaders(input.fileRef, stat, input.disposition, canReadRange);
|
|
1786
|
+
const etag = headers.get("etag");
|
|
1787
|
+
if (matchesIfNoneMatch(input.ifNoneMatchHeader, etag)) {
|
|
1788
|
+
headers.delete("content-length");
|
|
1789
|
+
return new Response(null, { status: 304, headers });
|
|
1790
|
+
}
|
|
1791
|
+
if (canReadRange && input.rangeHeader && (input.ifRangeHeader == null || input.ifRangeHeader.trim() === etag)) {
|
|
1792
|
+
const range = parseSingleByteRange(input.rangeHeader, stat.sizeBytes);
|
|
1793
|
+
if (!range) {
|
|
1794
|
+
return rangeNotSatisfiableResponse(stat.sizeBytes);
|
|
1795
|
+
}
|
|
1796
|
+
const partialHeaders = partialFileContentHeaders(headers, range, stat.sizeBytes);
|
|
1797
|
+
if (input.head) {
|
|
1798
|
+
return new Response(null, { status: 206, headers: partialHeaders });
|
|
1799
|
+
}
|
|
1800
|
+
try {
|
|
1801
|
+
const stream = await input.blobStorage.openRange(input.fileRef.blobId, range);
|
|
1802
|
+
return new Response(stream, { status: 206, headers: partialHeaders });
|
|
1803
|
+
} catch (error) {
|
|
1804
|
+
if (error instanceof BlobStorageError) {
|
|
1805
|
+
return null;
|
|
1806
|
+
}
|
|
1807
|
+
throw error;
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
if (input.head) {
|
|
1811
|
+
return new Response(null, { headers });
|
|
1812
|
+
}
|
|
1813
|
+
try {
|
|
1814
|
+
const stream = await input.blobStorage.open(input.fileRef.blobId);
|
|
1815
|
+
return new Response(stream, { headers });
|
|
1816
|
+
} catch (error) {
|
|
1817
|
+
if (error instanceof BlobStorageError) {
|
|
1818
|
+
return null;
|
|
1819
|
+
}
|
|
1820
|
+
throw error;
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
async function createContextualFileContentResponse(input) {
|
|
1824
|
+
const missingMessage = input.missingMessage ?? "File not found";
|
|
1825
|
+
const invalidQueryMessage = input.invalidQueryMessage ?? "Invalid file content query";
|
|
1826
|
+
try {
|
|
1827
|
+
const parsed = input.querySchema.parse(input.query);
|
|
1828
|
+
const root = await input.resolveRoot(parsed);
|
|
1829
|
+
if (root === null || root === undefined) {
|
|
1830
|
+
return fileContentNotFound(input.set, missingMessage);
|
|
1831
|
+
}
|
|
1832
|
+
const fileRef = resolveFileRefAtPath(root, parsed.path);
|
|
1833
|
+
if (!fileRef) {
|
|
1834
|
+
return fileContentNotFound(input.set, missingMessage);
|
|
1835
|
+
}
|
|
1836
|
+
const response = await createFileContentResponse({
|
|
1837
|
+
blobStorage: input.blobStorage,
|
|
1838
|
+
fileRef,
|
|
1839
|
+
disposition: parsed.disposition,
|
|
1840
|
+
head: input.head,
|
|
1841
|
+
rangeHeader: input.request.headers.get("range"),
|
|
1842
|
+
ifNoneMatchHeader: input.request.headers.get("if-none-match"),
|
|
1843
|
+
ifRangeHeader: input.request.headers.get("if-range")
|
|
1844
|
+
});
|
|
1845
|
+
if (!response) {
|
|
1846
|
+
return fileContentNotFound(input.set, missingMessage);
|
|
1847
|
+
}
|
|
1848
|
+
return response;
|
|
1849
|
+
} catch (error) {
|
|
1850
|
+
if (error instanceof ZodError) {
|
|
1851
|
+
input.set.status = 400;
|
|
1852
|
+
return { error: invalidQueryMessage };
|
|
1853
|
+
}
|
|
1854
|
+
if (input.hideError?.(error)) {
|
|
1855
|
+
return fileContentNotFound(input.set, missingMessage);
|
|
1856
|
+
}
|
|
1857
|
+
throw error;
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
function fileContentNotFound(set, message) {
|
|
1861
|
+
set.status = 404;
|
|
1862
|
+
return { error: message };
|
|
1863
|
+
}
|
|
1864
|
+
function matchesIfNoneMatch(header, etag) {
|
|
1865
|
+
return header?.trim() === "*" || (header?.split(",").some((value) => value.trim().replace(/^W\//, "") === etag) ?? false);
|
|
1866
|
+
}
|
|
1867
|
+
var INLINE_MEDIA_TYPES = new Set([
|
|
1868
|
+
"application/json",
|
|
1869
|
+
"application/pdf",
|
|
1870
|
+
"image/avif",
|
|
1871
|
+
"image/bmp",
|
|
1872
|
+
"image/gif",
|
|
1873
|
+
"image/jpeg",
|
|
1874
|
+
"image/png",
|
|
1875
|
+
"image/webp",
|
|
1876
|
+
"text/markdown",
|
|
1877
|
+
"text/plain"
|
|
1878
|
+
]);
|
|
1879
|
+
var FILE_CONTENT_SECURITY_POLICY = "default-src 'none'; style-src 'unsafe-inline'; sandbox";
|
|
1880
|
+
var PDF_CONTENT_SECURITY_POLICY = "default-src 'none'; style-src 'unsafe-inline'; object-src 'self'";
|
|
1881
|
+
function fileContentHeaders(fileRef, stat, requestedDisposition, canReadRange) {
|
|
1882
|
+
const mediaType = canonicalMediaType(fileRef.mediaType) ?? "application/octet-stream";
|
|
1883
|
+
const baseType = mediaType.split(";", 1)[0];
|
|
1884
|
+
const disposition = (requestedDisposition ?? "inline") === "inline" && INLINE_MEDIA_TYPES.has(baseType) ? "inline" : "attachment";
|
|
1885
|
+
const headers = new Headers;
|
|
1886
|
+
headers.set("content-type", mediaType);
|
|
1887
|
+
headers.set("content-length", stat.sizeBytes.toString());
|
|
1888
|
+
headers.set("content-disposition", contentDispositionHeader(disposition, fileNameFor(fileRef)));
|
|
1889
|
+
headers.set("content-security-policy", baseType === "application/pdf" ? PDF_CONTENT_SECURITY_POLICY : FILE_CONTENT_SECURITY_POLICY);
|
|
1890
|
+
const representation = JSON.stringify([
|
|
1891
|
+
fileRef.digest,
|
|
1892
|
+
mediaType,
|
|
1893
|
+
headers.get("content-disposition")
|
|
1894
|
+
]);
|
|
1895
|
+
headers.set("etag", `"sha256:${createHash2("sha256").update(representation).digest("hex")}"`);
|
|
1896
|
+
headers.set("x-content-type-options", "nosniff");
|
|
1897
|
+
headers.set("cache-control", "private, no-cache");
|
|
1898
|
+
if (canReadRange) {
|
|
1899
|
+
headers.set("accept-ranges", "bytes");
|
|
1900
|
+
}
|
|
1901
|
+
return headers;
|
|
1902
|
+
}
|
|
1903
|
+
function parseSingleByteRange(header, sizeBytes) {
|
|
1904
|
+
const normalized = header.trim();
|
|
1905
|
+
if (!normalized.startsWith("bytes=") || normalized.includes(",")) {
|
|
1906
|
+
return null;
|
|
1907
|
+
}
|
|
1908
|
+
if (sizeBytes <= 0) {
|
|
1909
|
+
return null;
|
|
1910
|
+
}
|
|
1911
|
+
const spec = normalized.slice("bytes=".length).trim();
|
|
1912
|
+
const match = spec.match(/^(\d*)-(\d*)$/);
|
|
1913
|
+
if (!match) {
|
|
1914
|
+
return null;
|
|
1915
|
+
}
|
|
1916
|
+
const [, rawStart, rawEnd] = match;
|
|
1917
|
+
if (!rawStart && !rawEnd) {
|
|
1918
|
+
return null;
|
|
1919
|
+
}
|
|
1920
|
+
if (!rawStart) {
|
|
1921
|
+
const suffixLength = Number(rawEnd);
|
|
1922
|
+
if (!Number.isSafeInteger(suffixLength) || suffixLength <= 0) {
|
|
1923
|
+
return null;
|
|
1924
|
+
}
|
|
1925
|
+
return {
|
|
1926
|
+
start: Math.max(sizeBytes - suffixLength, 0),
|
|
1927
|
+
endInclusive: sizeBytes - 1
|
|
1928
|
+
};
|
|
1929
|
+
}
|
|
1930
|
+
const start = Number(rawStart);
|
|
1931
|
+
if (!Number.isSafeInteger(start) || start >= sizeBytes) {
|
|
1932
|
+
return null;
|
|
1933
|
+
}
|
|
1934
|
+
const requestedEnd = rawEnd ? Number(rawEnd) : sizeBytes - 1;
|
|
1935
|
+
if (!Number.isSafeInteger(requestedEnd) || requestedEnd < start) {
|
|
1936
|
+
return null;
|
|
1937
|
+
}
|
|
1938
|
+
return {
|
|
1939
|
+
start,
|
|
1940
|
+
endInclusive: Math.min(requestedEnd, sizeBytes - 1)
|
|
1941
|
+
};
|
|
1942
|
+
}
|
|
1943
|
+
function partialFileContentHeaders(baseHeaders, range, sizeBytes) {
|
|
1944
|
+
const headers = new Headers(baseHeaders);
|
|
1945
|
+
headers.set("content-length", (range.endInclusive - range.start + 1).toString());
|
|
1946
|
+
headers.set("content-range", `bytes ${range.start}-${range.endInclusive}/${sizeBytes}`);
|
|
1947
|
+
return headers;
|
|
1948
|
+
}
|
|
1949
|
+
function rangeNotSatisfiableResponse(sizeBytes) {
|
|
1950
|
+
const headers = new Headers;
|
|
1951
|
+
headers.set("accept-ranges", "bytes");
|
|
1952
|
+
headers.set("content-range", `bytes */${sizeBytes}`);
|
|
1953
|
+
return new Response(null, { status: 416, headers });
|
|
1954
|
+
}
|
|
1955
|
+
function contentDispositionHeader(disposition, fileName) {
|
|
1956
|
+
const asciiFileName = fileName.replace(/[^\x20-\x7e]/g, "_").replaceAll('"', "'");
|
|
1957
|
+
return `${disposition}; filename="${asciiFileName}"; filename*=UTF-8''${encodeURIComponent(fileName)}`;
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1736
1960
|
// src/schemas/files.ts
|
|
1737
1961
|
import { canonicalMediaType as canonicalMediaType2 } from "@sixb/core/internal/blob-storage";
|
|
1738
1962
|
import { z as z4 } from "zod";
|
|
@@ -1810,216 +2034,15 @@ var FileContentQuerySchema = z4.object({
|
|
|
1810
2034
|
v: z4.string().optional().describe("Client cache key; the route still resolves the current file")
|
|
1811
2035
|
});
|
|
1812
2036
|
|
|
1813
|
-
// src/utils/http.ts
|
|
1814
|
-
import {
|
|
1815
|
-
AuthorizationError,
|
|
1816
|
-
OntologyNotFoundError,
|
|
1817
|
-
OntologyValidationError
|
|
1818
|
-
} from "@sixb/core";
|
|
1819
|
-
import { isSixbError } from "@sixb/core/internal/errors";
|
|
1820
|
-
import {
|
|
1821
|
-
FileUploadSessionError,
|
|
1822
|
-
ObjectNotFoundError
|
|
1823
|
-
} from "@sixb/core/storage";
|
|
1824
|
-
|
|
1825
|
-
// src/utils/request-body.ts
|
|
1826
|
-
class RequestBodyTooLargeError extends Error {
|
|
1827
|
-
limitBytes;
|
|
1828
|
-
name = "RequestBodyTooLargeError";
|
|
1829
|
-
constructor(limitBytes, message = `Request body exceeds the ${limitBytes} byte limit.`) {
|
|
1830
|
-
super(message);
|
|
1831
|
-
this.limitBytes = limitBytes;
|
|
1832
|
-
}
|
|
1833
|
-
}
|
|
1834
|
-
async function readRequestBodyWithLimit(request, limitBytes, tooLargeMessage) {
|
|
1835
|
-
const contentLength = request.headers.get("content-length");
|
|
1836
|
-
if (contentLength !== null) {
|
|
1837
|
-
const declared = Number(contentLength);
|
|
1838
|
-
if (Number.isSafeInteger(declared) && declared > limitBytes) {
|
|
1839
|
-
throw new RequestBodyTooLargeError(limitBytes, tooLargeMessage);
|
|
1840
|
-
}
|
|
1841
|
-
}
|
|
1842
|
-
if (!request.body) {
|
|
1843
|
-
return new Uint8Array(0);
|
|
1844
|
-
}
|
|
1845
|
-
const reader = request.body.getReader();
|
|
1846
|
-
const chunks = [];
|
|
1847
|
-
let total = 0;
|
|
1848
|
-
while (true) {
|
|
1849
|
-
const { done, value } = await reader.read();
|
|
1850
|
-
if (done) {
|
|
1851
|
-
break;
|
|
1852
|
-
}
|
|
1853
|
-
total += value.byteLength;
|
|
1854
|
-
if (total > limitBytes) {
|
|
1855
|
-
await reader.cancel();
|
|
1856
|
-
throw new RequestBodyTooLargeError(limitBytes, tooLargeMessage);
|
|
1857
|
-
}
|
|
1858
|
-
chunks.push(value);
|
|
1859
|
-
}
|
|
1860
|
-
const result = new Uint8Array(total);
|
|
1861
|
-
let offset = 0;
|
|
1862
|
-
for (const chunk of chunks) {
|
|
1863
|
-
result.set(chunk, offset);
|
|
1864
|
-
offset += chunk.byteLength;
|
|
1865
|
-
}
|
|
1866
|
-
return result;
|
|
1867
|
-
}
|
|
1868
|
-
|
|
1869
|
-
// src/utils/http.ts
|
|
1870
|
-
var HTTP_STATUS_BY_ERROR_CODE = {
|
|
1871
|
-
"connector.adapter_invalid": 502,
|
|
1872
|
-
"connector.authorization_invalid": 400,
|
|
1873
|
-
"connector.authorization_required": 409,
|
|
1874
|
-
"connector.configuration_invalid": 400,
|
|
1875
|
-
"connector.credentials_unavailable": 503,
|
|
1876
|
-
"connector.not_found": 404,
|
|
1877
|
-
"connector.operation_conflict": 409,
|
|
1878
|
-
"connector.operation_in_progress": 409,
|
|
1879
|
-
"connector.provider_failed": 502,
|
|
1880
|
-
"connector.provider_unavailable": 503,
|
|
1881
|
-
"connector.replacement_required": 409,
|
|
1882
|
-
"connector.revocation_pending": 409,
|
|
1883
|
-
"dataset.not_found": 404,
|
|
1884
|
-
"dataset.version_not_found": 404,
|
|
1885
|
-
"ai.usage_limit_exceeded": 429,
|
|
1886
|
-
"ai.usage_limit_unavailable": 429
|
|
1887
|
-
};
|
|
1888
|
-
function toIsoString(value) {
|
|
1889
|
-
return value.toISOString();
|
|
1890
|
-
}
|
|
1891
|
-
function parseDate(value) {
|
|
1892
|
-
if (!value) {
|
|
1893
|
-
return;
|
|
1894
|
-
}
|
|
1895
|
-
const parsed = new Date(value);
|
|
1896
|
-
if (Number.isNaN(parsed.getTime())) {
|
|
1897
|
-
throw new Error(`Invalid date: ${value}`);
|
|
1898
|
-
}
|
|
1899
|
-
return parsed;
|
|
1900
|
-
}
|
|
1901
|
-
function parseOptionalInt(value) {
|
|
1902
|
-
if (value === undefined) {
|
|
1903
|
-
return;
|
|
1904
|
-
}
|
|
1905
|
-
const parsed = Number.parseInt(value, 10);
|
|
1906
|
-
if (!Number.isFinite(parsed)) {
|
|
1907
|
-
throw new Error(`Invalid integer: ${value}`);
|
|
1908
|
-
}
|
|
1909
|
-
return parsed;
|
|
1910
|
-
}
|
|
1911
|
-
function unconfiguredStorageResponse2(set, role) {
|
|
1912
|
-
set.status = 501;
|
|
1913
|
-
return { error: `[SixbServer] ${role} is not configured on this runtime.` };
|
|
1914
|
-
}
|
|
1915
|
-
function handleRouteError(error, set) {
|
|
1916
|
-
if (isSixbError(error)) {
|
|
1917
|
-
set.status = HTTP_STATUS_BY_ERROR_CODE[error.code] ?? 500;
|
|
1918
|
-
if (error.code === "ai.usage_limit_exceeded")
|
|
1919
|
-
setRetryAfterFromDetails(set, error.details);
|
|
1920
|
-
const exposesDetails = error.code === "ai.usage_limit_exceeded" || error.code === "ai.usage_limit_unavailable";
|
|
1921
|
-
return {
|
|
1922
|
-
error: error.message,
|
|
1923
|
-
code: error.code,
|
|
1924
|
-
...!exposesDetails || error.details === undefined ? {} : { details: error.details }
|
|
1925
|
-
};
|
|
1926
|
-
}
|
|
1927
|
-
if (error instanceof AuthorizationError) {
|
|
1928
|
-
set.status = 403;
|
|
1929
|
-
return { error: error.message };
|
|
1930
|
-
}
|
|
1931
|
-
if (error instanceof FileUploadSessionError) {
|
|
1932
|
-
set.status = fileUploadSessionErrorStatus(error.reason);
|
|
1933
|
-
return { error: error.message };
|
|
1934
|
-
}
|
|
1935
|
-
if (error instanceof RequestBodyTooLargeError) {
|
|
1936
|
-
set.status = 413;
|
|
1937
|
-
return { error: error.message };
|
|
1938
|
-
}
|
|
1939
|
-
if (error instanceof OntologyNotFoundError || error instanceof ObjectNotFoundError) {
|
|
1940
|
-
set.status = 404;
|
|
1941
|
-
return { error: error.message };
|
|
1942
|
-
}
|
|
1943
|
-
if (error instanceof OntologyValidationError) {
|
|
1944
|
-
set.status = 400;
|
|
1945
|
-
return { error: error.message };
|
|
1946
|
-
}
|
|
1947
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
1948
|
-
set.status = 400;
|
|
1949
|
-
return { error: message };
|
|
1950
|
-
}
|
|
1951
|
-
function setRetryAfterFromDetails(set, details) {
|
|
1952
|
-
if (typeof details !== "object" || details === null || Array.isArray(details))
|
|
1953
|
-
return;
|
|
1954
|
-
const resetAt = details.resetAt;
|
|
1955
|
-
if (typeof resetAt !== "string")
|
|
1956
|
-
return;
|
|
1957
|
-
const resetTime = Date.parse(resetAt);
|
|
1958
|
-
if (!Number.isFinite(resetTime))
|
|
1959
|
-
return;
|
|
1960
|
-
const seconds = String(Math.max(0, Math.ceil((resetTime - Date.now()) / 1000)));
|
|
1961
|
-
const headers = typeof set.headers === "object" && set.headers !== null ? set.headers : {};
|
|
1962
|
-
headers["Retry-After"] = seconds;
|
|
1963
|
-
set.headers = headers;
|
|
1964
|
-
}
|
|
1965
|
-
function fileUploadSessionErrorStatus(reason) {
|
|
1966
|
-
switch (reason) {
|
|
1967
|
-
case "not_found":
|
|
1968
|
-
return 404;
|
|
1969
|
-
case "expired":
|
|
1970
|
-
return 410;
|
|
1971
|
-
case "already_completed":
|
|
1972
|
-
case "already_aborted":
|
|
1973
|
-
return 409;
|
|
1974
|
-
}
|
|
1975
|
-
}
|
|
1976
|
-
|
|
1977
2037
|
// src/routes/action-runs.ts
|
|
1978
2038
|
var ActionRunFileContentQuerySchema = FileContentQuerySchema.extend({
|
|
1979
2039
|
path: z5.string().min(1).regex(/^\/(?:params|writeback\/result)(?:\/|$)/, "Action run file content paths must start with /params/ or /writeback/result/")
|
|
1980
2040
|
});
|
|
1981
|
-
function serializeActionRunSummary(run) {
|
|
1982
|
-
return ActionRunSummarySchema.parse({
|
|
1983
|
-
id: run.id,
|
|
1984
|
-
projectId: run.projectId,
|
|
1985
|
-
actionId: run.actionId,
|
|
1986
|
-
subject: run.subject,
|
|
1987
|
-
status: run.status,
|
|
1988
|
-
phase: run.phase,
|
|
1989
|
-
queuedAt: toIsoString(run.queuedAt),
|
|
1990
|
-
startedAt: run.startedAt ? toIsoString(run.startedAt) : undefined,
|
|
1991
|
-
finishedAt: run.finishedAt ? toIsoString(run.finishedAt) : undefined,
|
|
1992
|
-
error: run.error
|
|
1993
|
-
});
|
|
1994
|
-
}
|
|
1995
|
-
function serializeActionRunDetail(run) {
|
|
1996
|
-
return ActionRunDetailSchema.parse({
|
|
1997
|
-
...serializeActionRunSummary(run),
|
|
1998
|
-
params: run.params,
|
|
1999
|
-
writeback: run.writeback ? run.writeback.status === "succeeded" ? {
|
|
2000
|
-
status: "succeeded",
|
|
2001
|
-
completedAt: toIsoString(run.writeback.completedAt),
|
|
2002
|
-
result: run.writeback.result
|
|
2003
|
-
} : {
|
|
2004
|
-
status: "failed",
|
|
2005
|
-
completedAt: toIsoString(run.writeback.completedAt),
|
|
2006
|
-
error: run.writeback.error
|
|
2007
|
-
} : undefined,
|
|
2008
|
-
effects: run.effects ? run.effects.status === "succeeded" ? {
|
|
2009
|
-
status: "succeeded",
|
|
2010
|
-
completedAt: toIsoString(run.effects.completedAt)
|
|
2011
|
-
} : {
|
|
2012
|
-
status: "failed",
|
|
2013
|
-
completedAt: toIsoString(run.effects.completedAt),
|
|
2014
|
-
error: run.effects.error
|
|
2015
|
-
} : undefined
|
|
2016
|
-
});
|
|
2017
|
-
}
|
|
2018
2041
|
async function actionRunFileContentResponse(host, context, options = {}) {
|
|
2019
2042
|
const sixb = requireRequestSixb(context);
|
|
2020
2043
|
const storage = host.storage.actionRuns;
|
|
2021
2044
|
if (!storage) {
|
|
2022
|
-
return
|
|
2045
|
+
return unconfiguredStorageResponse(context.set, "Action run storage");
|
|
2023
2046
|
}
|
|
2024
2047
|
return createContextualFileContentResponse({
|
|
2025
2048
|
blobStorage: host.blobStorage,
|
|
@@ -2041,7 +2064,7 @@ function registerActionRunRoutes(app, host) {
|
|
|
2041
2064
|
try {
|
|
2042
2065
|
const storage = host.storage.actionRuns;
|
|
2043
2066
|
if (!storage) {
|
|
2044
|
-
return
|
|
2067
|
+
return unconfiguredStorageResponse(set, "Action run storage");
|
|
2045
2068
|
}
|
|
2046
2069
|
const parsed = ActionRunsQuerySchema.parse(query);
|
|
2047
2070
|
const limit = parseOptionalInt(parsed.limit);
|
|
@@ -2084,7 +2107,7 @@ function registerActionRunRoutes(app, host) {
|
|
|
2084
2107
|
try {
|
|
2085
2108
|
const storage = host.storage.actionRuns;
|
|
2086
2109
|
if (!storage) {
|
|
2087
|
-
return
|
|
2110
|
+
return unconfiguredStorageResponse(set, "Action run storage");
|
|
2088
2111
|
}
|
|
2089
2112
|
const run = await sixb.actions.runs.getById(params.runId);
|
|
2090
2113
|
if (!run) {
|
|
@@ -2193,19 +2216,18 @@ function registerActionRoutes(app, host) {
|
|
|
2193
2216
|
security: accessTokenSecurityRequirement("getAction")
|
|
2194
2217
|
}
|
|
2195
2218
|
}).post("/api/actions/:actionId", async (context) => {
|
|
2196
|
-
const { params, body, set } = context;
|
|
2219
|
+
const { params, body, set, request, server } = context;
|
|
2220
|
+
server?.timeout(request, 0);
|
|
2197
2221
|
const sixb = requireRequestSixb(context);
|
|
2198
2222
|
try {
|
|
2199
2223
|
const parsedBody = RequestActionBodySchema.parse(body);
|
|
2200
|
-
const
|
|
2224
|
+
const run = await sixb.actions.request({
|
|
2201
2225
|
actionId: params.actionId,
|
|
2202
2226
|
subject: parsedBody.subject,
|
|
2203
2227
|
params: parsedBody.params,
|
|
2204
2228
|
runId: parsedBody.runId
|
|
2205
|
-
};
|
|
2206
|
-
|
|
2207
|
-
set.status = 202;
|
|
2208
|
-
return RequestActionResponseSchema.parse(result);
|
|
2229
|
+
});
|
|
2230
|
+
return serializeActionRunDetail(run);
|
|
2209
2231
|
} catch (error) {
|
|
2210
2232
|
return handleRouteError(error, set);
|
|
2211
2233
|
}
|
|
@@ -2213,13 +2235,17 @@ function registerActionRoutes(app, host) {
|
|
|
2213
2235
|
params: ActionIdParamsSchema,
|
|
2214
2236
|
body: RequestActionBodySchema,
|
|
2215
2237
|
response: {
|
|
2216
|
-
|
|
2238
|
+
200: ActionRunDetailSchema,
|
|
2217
2239
|
400: ErrorResponseSchema,
|
|
2218
2240
|
403: ErrorResponseSchema,
|
|
2219
|
-
404: ErrorResponseSchema
|
|
2241
|
+
404: ErrorResponseSchema,
|
|
2242
|
+
409: ActionRunInProgressResponseSchema,
|
|
2243
|
+
500: ActionRequestFailedResponseSchema,
|
|
2244
|
+
503: RuntimeStoppingResponseSchema
|
|
2220
2245
|
},
|
|
2221
2246
|
detail: {
|
|
2222
2247
|
summary: "Request an action",
|
|
2248
|
+
description: "Runs the action and returns its terminal run. A run that fails is returned with " + "status `failed`. Its effects run after the response, which does not wait for them. " + "An error response usually means no run was requested, but a 500 can follow a run " + "that started: request again with the same `runId` to get its record if it was " + "written. A `runId` that was already recorded returns that run, and 409 while this " + "server still runs it. 503 means the server is stopping and started nothing.",
|
|
2223
2249
|
tags: [OPENAPI_TAGS.actions.name],
|
|
2224
2250
|
operationId: "requestAction",
|
|
2225
2251
|
security: accessTokenSecurityRequirement("requestAction")
|
|
@@ -2253,12 +2279,10 @@ function registerFileRoutes(app, host) {
|
|
|
2253
2279
|
const uploadSessions = host.storage.fileUploadSessions;
|
|
2254
2280
|
return app.post("/api/files", async ({ request, set }) => {
|
|
2255
2281
|
try {
|
|
2256
|
-
const
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
}
|
|
2261
|
-
const form = await request.formData();
|
|
2282
|
+
const bytes = await readRequestBodyWithLimit(request, DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES, `File upload request exceeds the ${DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES} byte limit.`);
|
|
2283
|
+
const form = await new Response(bytes, {
|
|
2284
|
+
headers: { "content-type": request.headers.get("content-type") ?? "" }
|
|
2285
|
+
}).formData();
|
|
2262
2286
|
const file = form.get("file");
|
|
2263
2287
|
const logicalPath = form.get("logicalPath");
|
|
2264
2288
|
if (!(file instanceof File)) {
|
|
@@ -2321,7 +2345,7 @@ function registerFileRoutes(app, host) {
|
|
|
2321
2345
|
const { body, set } = context;
|
|
2322
2346
|
try {
|
|
2323
2347
|
if (!uploadSessions) {
|
|
2324
|
-
return
|
|
2348
|
+
return unconfiguredStorageResponse(set, "File upload session storage");
|
|
2325
2349
|
}
|
|
2326
2350
|
const parsed = CreateFileUploadBodySchema.parse(body);
|
|
2327
2351
|
const principal = requireRequestSixb(context).execution.requestedBy ?? SYSTEM_PRINCIPAL;
|
|
@@ -2372,7 +2396,7 @@ function registerFileRoutes(app, host) {
|
|
|
2372
2396
|
const { params, request, set } = context;
|
|
2373
2397
|
try {
|
|
2374
2398
|
if (!uploadSessions) {
|
|
2375
|
-
return
|
|
2399
|
+
return unconfiguredStorageResponse(set, "File upload session storage");
|
|
2376
2400
|
}
|
|
2377
2401
|
const principal = requireRequestSixb(context).execution.requestedBy ?? SYSTEM_PRINCIPAL;
|
|
2378
2402
|
const session = await uploadSessions.getForPrincipal(params.uploadId, principal);
|
|
@@ -2388,7 +2412,7 @@ function registerFileRoutes(app, host) {
|
|
|
2388
2412
|
set.status = 400;
|
|
2389
2413
|
return { error: contentLengthSizeError };
|
|
2390
2414
|
}
|
|
2391
|
-
const uploadBytes =
|
|
2415
|
+
const uploadBytes = await readRequestBodyWithLimit(request, DEFAULT_SIMPLE_FILE_UPLOAD_BYTES);
|
|
2392
2416
|
if (uploadBytes.byteLength === 0) {
|
|
2393
2417
|
set.status = 400;
|
|
2394
2418
|
return { error: "Expected upload content body." };
|
|
@@ -2417,14 +2441,14 @@ function registerFileRoutes(app, host) {
|
|
|
2417
2441
|
}
|
|
2418
2442
|
}, {
|
|
2419
2443
|
params: FileUploadIdParamsSchema,
|
|
2420
|
-
parse:
|
|
2421
|
-
error: mapUploadContentError,
|
|
2444
|
+
parse: "none",
|
|
2422
2445
|
response: {
|
|
2423
2446
|
200: SuccessResponseSchema,
|
|
2424
2447
|
400: ErrorResponseSchema,
|
|
2425
2448
|
404: ErrorResponseSchema,
|
|
2426
2449
|
409: ErrorResponseSchema,
|
|
2427
2450
|
410: ErrorResponseSchema,
|
|
2451
|
+
413: ErrorResponseSchema,
|
|
2428
2452
|
501: ErrorResponseSchema
|
|
2429
2453
|
},
|
|
2430
2454
|
detail: {
|
|
@@ -2448,7 +2472,7 @@ function registerFileRoutes(app, host) {
|
|
|
2448
2472
|
const { params, set } = context;
|
|
2449
2473
|
try {
|
|
2450
2474
|
if (!uploadSessions) {
|
|
2451
|
-
return
|
|
2475
|
+
return unconfiguredStorageResponse(set, "File upload session storage");
|
|
2452
2476
|
}
|
|
2453
2477
|
const principal = requireRequestSixb(context).execution.requestedBy ?? SYSTEM_PRINCIPAL;
|
|
2454
2478
|
const session = await uploadSessions.getForPrincipal(params.uploadId, principal);
|
|
@@ -2498,7 +2522,7 @@ function registerFileRoutes(app, host) {
|
|
|
2498
2522
|
const { body, params, set } = context;
|
|
2499
2523
|
try {
|
|
2500
2524
|
if (!uploadSessions) {
|
|
2501
|
-
return
|
|
2525
|
+
return unconfiguredStorageResponse(set, "File upload session storage");
|
|
2502
2526
|
}
|
|
2503
2527
|
const principal = requireRequestSixb(context).execution.requestedBy ?? SYSTEM_PRINCIPAL;
|
|
2504
2528
|
const parsed = CompleteFileUploadBodySchema.parse(body ?? {});
|
|
@@ -2554,7 +2578,7 @@ function registerFileRoutes(app, host) {
|
|
|
2554
2578
|
const { params, set } = context;
|
|
2555
2579
|
try {
|
|
2556
2580
|
if (!uploadSessions) {
|
|
2557
|
-
return
|
|
2581
|
+
return unconfiguredStorageResponse(set, "File upload session storage");
|
|
2558
2582
|
}
|
|
2559
2583
|
const principal = requireRequestSixb(context).execution.requestedBy ?? SYSTEM_PRINCIPAL;
|
|
2560
2584
|
const session = await uploadSessions.getForPrincipal(params.uploadId, principal);
|
|
@@ -2625,27 +2649,6 @@ function fileUploadResponse(session) {
|
|
|
2625
2649
|
expiresAt: session.expiresAt.toISOString()
|
|
2626
2650
|
};
|
|
2627
2651
|
}
|
|
2628
|
-
function readCappedUploadBody(context) {
|
|
2629
|
-
return readRequestBodyWithLimit(context.request, DEFAULT_SIMPLE_FILE_UPLOAD_BYTES);
|
|
2630
|
-
}
|
|
2631
|
-
function readParsedUploadBytes(context) {
|
|
2632
|
-
return context.body instanceof Uint8Array ? context.body : new Uint8Array(0);
|
|
2633
|
-
}
|
|
2634
|
-
function mapUploadContentError(context) {
|
|
2635
|
-
const tooLarge = asRequestBodyTooLarge(context.error);
|
|
2636
|
-
if (tooLarge) {
|
|
2637
|
-
context.set.status = 413;
|
|
2638
|
-
return { error: tooLarge.message };
|
|
2639
|
-
}
|
|
2640
|
-
return;
|
|
2641
|
-
}
|
|
2642
|
-
function asRequestBodyTooLarge(error) {
|
|
2643
|
-
if (error instanceof RequestBodyTooLargeError) {
|
|
2644
|
-
return error;
|
|
2645
|
-
}
|
|
2646
|
-
const cause = error?.cause;
|
|
2647
|
-
return cause instanceof RequestBodyTooLargeError ? cause : undefined;
|
|
2648
|
-
}
|
|
2649
2652
|
function terminalSessionError(status) {
|
|
2650
2653
|
return new FileUploadSessionError2(status === "completed" ? "already_completed" : "already_aborted", `File upload session is already ${status}.`);
|
|
2651
2654
|
}
|
|
@@ -2704,17 +2707,6 @@ function expectedSizeBytesError(session, actualSizeBytes) {
|
|
|
2704
2707
|
function expectedSizeBytesValueError(expectedSizeBytes, actualSizeBytes) {
|
|
2705
2708
|
return expectedSizeBytes !== undefined && actualSizeBytes !== undefined && actualSizeBytes !== expectedSizeBytes ? `File upload size mismatch: expected ${expectedSizeBytes} bytes, received ${actualSizeBytes}.` : null;
|
|
2706
2709
|
}
|
|
2707
|
-
function requestSizeLimitError(request, maxSizeBytes) {
|
|
2708
|
-
const value = request.headers.get("content-length");
|
|
2709
|
-
if (value === null) {
|
|
2710
|
-
return null;
|
|
2711
|
-
}
|
|
2712
|
-
const sizeBytes = Number(value);
|
|
2713
|
-
if (!Number.isSafeInteger(sizeBytes) || sizeBytes <= maxSizeBytes) {
|
|
2714
|
-
return null;
|
|
2715
|
-
}
|
|
2716
|
-
return `File upload request exceeds the ${maxSizeBytes} byte limit.`;
|
|
2717
|
-
}
|
|
2718
2710
|
function expectedContentLengthError(session, request) {
|
|
2719
2711
|
if (session.expectedSizeBytes === undefined) {
|
|
2720
2712
|
return null;
|
|
@@ -2781,9 +2773,9 @@ async function handleAgentApiGatewayRequest(input) {
|
|
|
2781
2773
|
}
|
|
2782
2774
|
let body;
|
|
2783
2775
|
try {
|
|
2784
|
-
body = await
|
|
2776
|
+
body = await readGatewayRequestBody(input.request, upstreamPath);
|
|
2785
2777
|
} catch (error) {
|
|
2786
|
-
if (error instanceof
|
|
2778
|
+
if (error instanceof RequestBodyTooLargeError) {
|
|
2787
2779
|
return jsonError(413, error.message);
|
|
2788
2780
|
}
|
|
2789
2781
|
throw error;
|
|
@@ -2957,24 +2949,14 @@ function copyHeader(source, target, name) {
|
|
|
2957
2949
|
target.set(name, value);
|
|
2958
2950
|
}
|
|
2959
2951
|
}
|
|
2960
|
-
async function
|
|
2952
|
+
async function readGatewayRequestBody(request, upstreamPath) {
|
|
2961
2953
|
if (!request.body || request.method === "GET" || request.method === "HEAD") {
|
|
2962
2954
|
return;
|
|
2963
2955
|
}
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
let total = 0;
|
|
2967
|
-
while (true) {
|
|
2968
|
-
const { done, value } = await reader.read();
|
|
2969
|
-
if (done)
|
|
2970
|
-
break;
|
|
2971
|
-
total += value.byteLength;
|
|
2972
|
-
if (total > maxBytes) {
|
|
2973
|
-
throw new PayloadTooLargeError(maxBytes === MAX_AGENT_API_BODY_BYTES ? "Agent API gateway request body exceeds 1MB." : `Agent API gateway file upload request body exceeds the ${maxBytes} byte limit.`);
|
|
2974
|
-
}
|
|
2975
|
-
chunks.push(value);
|
|
2956
|
+
if (isSimpleFileUpload(request.method, upstreamPath)) {
|
|
2957
|
+
return readRequestBodyWithLimit(request, DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES, `Agent API gateway file upload request body exceeds the ${DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES} byte limit.`);
|
|
2976
2958
|
}
|
|
2977
|
-
return
|
|
2959
|
+
return readRequestBodyWithLimit(request, MAX_AGENT_API_BODY_BYTES, "Agent API gateway request body exceeds 1MB.");
|
|
2978
2960
|
}
|
|
2979
2961
|
function isSimpleFileUpload(method, pathname) {
|
|
2980
2962
|
return method === "POST" && normalizeRoutePath4(pathname) === "/api/files";
|
|
@@ -2983,23 +2965,10 @@ function matchesWorkflowRunStart(pathname) {
|
|
|
2983
2965
|
const segments = pathSegmentsFor(pathname);
|
|
2984
2966
|
return segments.length === 4 && segments[0] === "api" && segments[1] === "workflows" && segments[3] === "runs";
|
|
2985
2967
|
}
|
|
2986
|
-
function concatChunks(chunks, total) {
|
|
2987
|
-
const buffer = new ArrayBuffer(total);
|
|
2988
|
-
const result = new Uint8Array(buffer);
|
|
2989
|
-
let offset = 0;
|
|
2990
|
-
for (const chunk of chunks) {
|
|
2991
|
-
result.set(chunk, offset);
|
|
2992
|
-
offset += chunk.byteLength;
|
|
2993
|
-
}
|
|
2994
|
-
return buffer;
|
|
2995
|
-
}
|
|
2996
2968
|
function jsonError(status, message) {
|
|
2997
2969
|
return Response.json({ error: message }, { status });
|
|
2998
2970
|
}
|
|
2999
2971
|
|
|
3000
|
-
class PayloadTooLargeError extends Error {
|
|
3001
|
-
}
|
|
3002
|
-
|
|
3003
2972
|
// src/routes/agents.ts
|
|
3004
2973
|
import {
|
|
3005
2974
|
AgentRequestError
|
|
@@ -3694,7 +3663,7 @@ function handleAgentRouteError(error, set) {
|
|
|
3694
3663
|
return handleRouteError(error, set);
|
|
3695
3664
|
}
|
|
3696
3665
|
function missingAgentStorageResponse(set) {
|
|
3697
|
-
return
|
|
3666
|
+
return unconfiguredStorageResponse(set, "Agent storage");
|
|
3698
3667
|
}
|
|
3699
3668
|
async function agentMessageFileContentResponse(host, context, options = {}) {
|
|
3700
3669
|
const authState = requestAuthState(context);
|
|
@@ -4454,7 +4423,7 @@ function registerAiAccountingRoutes(app, host) {
|
|
|
4454
4423
|
sixb.aiUsage.assertObservable();
|
|
4455
4424
|
const parsed = AiAccountingOverviewQuerySchema.parse(query);
|
|
4456
4425
|
if (!sixb.aiUsage.accountingConfigured) {
|
|
4457
|
-
return
|
|
4426
|
+
return unconfiguredStorageResponse(set, "AI cost storage");
|
|
4458
4427
|
}
|
|
4459
4428
|
const overview = await sixb.aiUsage.queryOverview({
|
|
4460
4429
|
from: new Date(parsed.from),
|
|
@@ -4489,7 +4458,7 @@ function registerAiAccountingRoutes(app, host) {
|
|
|
4489
4458
|
sixb.aiUsage.assertObservable();
|
|
4490
4459
|
const parsed = AiModelCallAccountingListQuerySchema.parse(query);
|
|
4491
4460
|
if (!sixb.aiUsage.accountingConfigured) {
|
|
4492
|
-
return
|
|
4461
|
+
return unconfiguredStorageResponse(set, "AI cost storage");
|
|
4493
4462
|
}
|
|
4494
4463
|
const result = await sixb.aiUsage.listModelCalls({
|
|
4495
4464
|
from: new Date(parsed.from),
|
|
@@ -4530,7 +4499,7 @@ function registerAiAccountingRoutes(app, host) {
|
|
|
4530
4499
|
try {
|
|
4531
4500
|
const sixb = requireRequestSixb(context);
|
|
4532
4501
|
if (!sixb.aiUsage.limitsConfigured) {
|
|
4533
|
-
return
|
|
4502
|
+
return unconfiguredStorageResponse(set, "AI limit storage");
|
|
4534
4503
|
}
|
|
4535
4504
|
const parsed = AiLimitListQuerySchema.parse(query);
|
|
4536
4505
|
const items = await sixb.aiUsage.listLimitPolicies({
|
|
@@ -4564,7 +4533,7 @@ function registerAiAccountingRoutes(app, host) {
|
|
|
4564
4533
|
const sixb = requireRequestSixb(context);
|
|
4565
4534
|
sixb.aiUsage.assertObservable();
|
|
4566
4535
|
if (!sixb.aiUsage.limitsConfigured) {
|
|
4567
|
-
return
|
|
4536
|
+
return unconfiguredStorageResponse(set, "AI limit storage");
|
|
4568
4537
|
}
|
|
4569
4538
|
const parsed = AiLimitStatusQuerySchema.parse(query);
|
|
4570
4539
|
const items = await sixb.aiUsage.listLimitStatuses({
|
|
@@ -4620,7 +4589,7 @@ function registerAiAccountingRoutes(app, host) {
|
|
|
4620
4589
|
const sixb = requireRequestSixb(context);
|
|
4621
4590
|
sixb.aiUsage.assertManageable();
|
|
4622
4591
|
if (!sixb.aiUsage.limitsConfigured) {
|
|
4623
|
-
return
|
|
4592
|
+
return unconfiguredStorageResponse(set, "AI limit storage");
|
|
4624
4593
|
}
|
|
4625
4594
|
const parsed = CreateAiLimitPolicyBodySchema.parse(body);
|
|
4626
4595
|
return serializeLimitPolicy(await sixb.aiUsage.createLimitPolicy(parsed));
|
|
@@ -4649,7 +4618,7 @@ function registerAiAccountingRoutes(app, host) {
|
|
|
4649
4618
|
const sixb = requireRequestSixb(context);
|
|
4650
4619
|
sixb.aiUsage.assertManageable();
|
|
4651
4620
|
if (!sixb.aiUsage.limitsConfigured) {
|
|
4652
|
-
return
|
|
4621
|
+
return unconfiguredStorageResponse(set, "AI limit storage");
|
|
4653
4622
|
}
|
|
4654
4623
|
const { limitId } = AiLimitPolicyParamsSchema.parse(params);
|
|
4655
4624
|
const parsed = UpdateAiLimitPolicyBodySchema.parse(body);
|
|
@@ -4680,7 +4649,7 @@ function registerAiAccountingRoutes(app, host) {
|
|
|
4680
4649
|
const sixb = requireRequestSixb(context);
|
|
4681
4650
|
sixb.aiUsage.assertManageable();
|
|
4682
4651
|
if (!sixb.aiUsage.limitsConfigured) {
|
|
4683
|
-
return
|
|
4652
|
+
return unconfiguredStorageResponse(set, "AI limit storage");
|
|
4684
4653
|
}
|
|
4685
4654
|
const { limitId } = AiLimitPolicyParamsSchema.parse(params);
|
|
4686
4655
|
if (!await sixb.aiUsage.deleteLimitPolicy(limitId)) {
|
|
@@ -4714,7 +4683,7 @@ function registerAiAccountingRoutes(app, host) {
|
|
|
4714
4683
|
const sixb = requireRequestSixb(context);
|
|
4715
4684
|
sixb.aiUsage.assertObservable();
|
|
4716
4685
|
if (!sixb.aiUsage.accountingConfigured)
|
|
4717
|
-
return
|
|
4686
|
+
return unconfiguredStorageResponse(set, "AI cost storage");
|
|
4718
4687
|
const result = await sixb.aiUsage.listModelCallGroups({
|
|
4719
4688
|
from: new Date(parsed.from),
|
|
4720
4689
|
to: new Date(parsed.to),
|
|
@@ -8192,7 +8161,7 @@ function registerPipelineRoutes(app, host) {
|
|
|
8192
8161
|
const parsed = PipelineRunsQuerySchema.parse(query);
|
|
8193
8162
|
const storage = host.storage.pipelineRuns;
|
|
8194
8163
|
if (!storage) {
|
|
8195
|
-
return
|
|
8164
|
+
return unconfiguredStorageResponse(set, "Pipeline run storage");
|
|
8196
8165
|
}
|
|
8197
8166
|
const result = await sixb.pipelines.runs.list({
|
|
8198
8167
|
pipelineId: parsed.pipelineId,
|
|
@@ -8229,7 +8198,7 @@ function registerPipelineRoutes(app, host) {
|
|
|
8229
8198
|
try {
|
|
8230
8199
|
const storage = host.storage.pipelineRuns;
|
|
8231
8200
|
if (!storage) {
|
|
8232
|
-
return
|
|
8201
|
+
return unconfiguredStorageResponse(set, "Pipeline run storage");
|
|
8233
8202
|
}
|
|
8234
8203
|
const run = await sixb.pipelines.runs.getById(params.runId);
|
|
8235
8204
|
if (!run) {
|
|
@@ -8555,7 +8524,7 @@ function registerProjectionRoutes(app, host) {
|
|
|
8555
8524
|
try {
|
|
8556
8525
|
const storage = host.storage.projectionRuns;
|
|
8557
8526
|
if (!storage) {
|
|
8558
|
-
return
|
|
8527
|
+
return unconfiguredStorageResponse(set, "Projection run storage");
|
|
8559
8528
|
}
|
|
8560
8529
|
const parsed = ProjectionRunsQuerySchema.parse(query);
|
|
8561
8530
|
const result = await sixb.projections.runs.list({
|
|
@@ -8596,7 +8565,7 @@ function registerProjectionRoutes(app, host) {
|
|
|
8596
8565
|
try {
|
|
8597
8566
|
const storage = host.storage.projectionRuns;
|
|
8598
8567
|
if (!storage) {
|
|
8599
|
-
return
|
|
8568
|
+
return unconfiguredStorageResponse(set, "Projection run storage");
|
|
8600
8569
|
}
|
|
8601
8570
|
const run = await sixb.projections.runs.getById(params.runId);
|
|
8602
8571
|
if (!run) {
|
|
@@ -8754,7 +8723,7 @@ function registerRuleRoutes(app, host) {
|
|
|
8754
8723
|
const parsed = RuleStatesQuerySchema.parse(query);
|
|
8755
8724
|
const storage = host.storage.rules;
|
|
8756
8725
|
if (!storage) {
|
|
8757
|
-
return
|
|
8726
|
+
return unconfiguredStorageResponse(set, "Rule state storage");
|
|
8758
8727
|
}
|
|
8759
8728
|
const result = await sixb.rules.states.list({
|
|
8760
8729
|
ruleId: parsed.ruleId,
|
|
@@ -9442,7 +9411,7 @@ function registerSyncRoutes(app, host) {
|
|
|
9442
9411
|
const parsed = SyncRunsQuerySchema.parse(query);
|
|
9443
9412
|
const storage = host.storage.syncRuns;
|
|
9444
9413
|
if (!storage) {
|
|
9445
|
-
return
|
|
9414
|
+
return unconfiguredStorageResponse(set, "Sync run storage");
|
|
9446
9415
|
}
|
|
9447
9416
|
const result = await sixb.syncs.runs.list({
|
|
9448
9417
|
syncId: parsed.syncId,
|
|
@@ -9773,7 +9742,7 @@ function registerWebhookRunRoutes(app, host) {
|
|
|
9773
9742
|
const parsed = WebhookRunsQuerySchema.parse(query);
|
|
9774
9743
|
const storage = host.storage.webhookRuns;
|
|
9775
9744
|
if (!storage) {
|
|
9776
|
-
return
|
|
9745
|
+
return unconfiguredStorageResponse(set, "Webhook run storage");
|
|
9777
9746
|
}
|
|
9778
9747
|
const result = await storage.list({
|
|
9779
9748
|
projectId: host.id,
|
|
@@ -10170,7 +10139,7 @@ async function workflowRunFileContentResponse(host, context, options = {}) {
|
|
|
10170
10139
|
const sixb = requireRequestSixb(context);
|
|
10171
10140
|
const storage = host.storage.workflowRuns;
|
|
10172
10141
|
if (!storage) {
|
|
10173
|
-
return
|
|
10142
|
+
return unconfiguredStorageResponse(context.set, "Workflow run storage");
|
|
10174
10143
|
}
|
|
10175
10144
|
return createContextualFileContentResponse({
|
|
10176
10145
|
blobStorage: host.blobStorage,
|
|
@@ -10189,7 +10158,7 @@ async function workflowNodeFileContentResponse(host, context, options = {}) {
|
|
|
10189
10158
|
const sixb = requireRequestSixb(context);
|
|
10190
10159
|
const storage = host.storage.workflowRuns;
|
|
10191
10160
|
if (!storage) {
|
|
10192
|
-
return
|
|
10161
|
+
return unconfiguredStorageResponse(context.set, "Workflow run storage");
|
|
10193
10162
|
}
|
|
10194
10163
|
return createContextualFileContentResponse({
|
|
10195
10164
|
blobStorage: host.blobStorage,
|
|
@@ -10437,7 +10406,7 @@ function registerWorkflowRoutes(app, host) {
|
|
|
10437
10406
|
const offset = parseOptionalInt(parsed.offset);
|
|
10438
10407
|
const storage = host.storage.workflowInterventions;
|
|
10439
10408
|
if (!storage) {
|
|
10440
|
-
return
|
|
10409
|
+
return unconfiguredStorageResponse(set, "Workflow intervention storage");
|
|
10441
10410
|
}
|
|
10442
10411
|
const result = await sixb.workflows.interventions.list({
|
|
10443
10412
|
workflowId: parsed.workflowId,
|
|
@@ -10479,7 +10448,7 @@ function registerWorkflowRoutes(app, host) {
|
|
|
10479
10448
|
try {
|
|
10480
10449
|
const storage = host.storage.workflowInterventions;
|
|
10481
10450
|
if (!storage) {
|
|
10482
|
-
return
|
|
10451
|
+
return unconfiguredStorageResponse(set, "Workflow intervention storage");
|
|
10483
10452
|
}
|
|
10484
10453
|
const intervention = await sixb.workflows.interventions.getById(params.interventionId);
|
|
10485
10454
|
if (!intervention) {
|
|
@@ -10509,7 +10478,7 @@ function registerWorkflowRoutes(app, host) {
|
|
|
10509
10478
|
try {
|
|
10510
10479
|
const storage = host.storage.workflowInterventions;
|
|
10511
10480
|
if (!storage) {
|
|
10512
|
-
return
|
|
10481
|
+
return unconfiguredStorageResponse(set, "Workflow intervention storage");
|
|
10513
10482
|
}
|
|
10514
10483
|
const intervention = await sixb.workflows.interventions.getById(params.interventionId);
|
|
10515
10484
|
if (!intervention) {
|
|
@@ -10579,11 +10548,11 @@ function registerWorkflowRoutes(app, host) {
|
|
|
10579
10548
|
try {
|
|
10580
10549
|
const interventionStorage = host.storage.workflowInterventions;
|
|
10581
10550
|
if (!interventionStorage) {
|
|
10582
|
-
return
|
|
10551
|
+
return unconfiguredStorageResponse(set, "Workflow intervention storage");
|
|
10583
10552
|
}
|
|
10584
10553
|
const runStorage = host.storage.workflowRuns;
|
|
10585
10554
|
if (!runStorage) {
|
|
10586
|
-
return
|
|
10555
|
+
return unconfiguredStorageResponse(set, "Workflow run storage");
|
|
10587
10556
|
}
|
|
10588
10557
|
const intervention = await sixb.workflows.interventions.getById(params.interventionId);
|
|
10589
10558
|
if (!intervention) {
|
|
@@ -10695,7 +10664,7 @@ function registerWorkflowRoutes(app, host) {
|
|
|
10695
10664
|
const offset = parseOptionalInt(parsed.offset);
|
|
10696
10665
|
const storage = host.storage.workflowRuns;
|
|
10697
10666
|
if (!storage) {
|
|
10698
|
-
return
|
|
10667
|
+
return unconfiguredStorageResponse(set, "Workflow run storage");
|
|
10699
10668
|
}
|
|
10700
10669
|
const result = await sixb.workflows.runs.list({
|
|
10701
10670
|
workflowId: parsed.workflowId,
|
|
@@ -10734,7 +10703,7 @@ function registerWorkflowRoutes(app, host) {
|
|
|
10734
10703
|
try {
|
|
10735
10704
|
const storage = host.storage.workflowRuns;
|
|
10736
10705
|
if (!storage) {
|
|
10737
|
-
return
|
|
10706
|
+
return unconfiguredStorageResponse(set, "Workflow run storage");
|
|
10738
10707
|
}
|
|
10739
10708
|
const run = await sixb.workflows.runs.getById(params.runId);
|
|
10740
10709
|
if (!run) {
|
|
@@ -10776,7 +10745,7 @@ function registerWorkflowRoutes(app, host) {
|
|
|
10776
10745
|
try {
|
|
10777
10746
|
const storage = host.storage.workflowRuns;
|
|
10778
10747
|
if (!storage) {
|
|
10779
|
-
return
|
|
10748
|
+
return unconfiguredStorageResponse(set, "Workflow run storage");
|
|
10780
10749
|
}
|
|
10781
10750
|
const run = await sixb.workflows.runs.getById(params.runId);
|
|
10782
10751
|
if (!run) {
|
|
@@ -10819,7 +10788,7 @@ function registerWorkflowRoutes(app, host) {
|
|
|
10819
10788
|
CancelWorkflowRunBodySchema.parse(body ?? {});
|
|
10820
10789
|
const storage = host.storage.workflowRuns;
|
|
10821
10790
|
if (!storage) {
|
|
10822
|
-
return
|
|
10791
|
+
return unconfiguredStorageResponse(set, "Workflow run storage");
|
|
10823
10792
|
}
|
|
10824
10793
|
const existing = await sixb.workflows.runs.getById(params.runId);
|
|
10825
10794
|
if (!existing) {
|
|
@@ -11020,7 +10989,7 @@ function registerWorkflowRoutes(app, host) {
|
|
|
11020
10989
|
const sixb = requireRequestSixb(context);
|
|
11021
10990
|
try {
|
|
11022
10991
|
if (!host.storage.workflowRuns) {
|
|
11023
|
-
return
|
|
10992
|
+
return unconfiguredStorageResponse(set, "Workflow run storage");
|
|
11024
10993
|
}
|
|
11025
10994
|
const parsedBody = RequestWorkflowRunBodySchema.parse(body);
|
|
11026
10995
|
const input = {
|
|
@@ -14407,7 +14376,6 @@ var SubscribeSchema2 = z34.object({
|
|
|
14407
14376
|
types: z34.array(z34.enum(EVENT_TYPES)).optional(),
|
|
14408
14377
|
objectTypeId: z34.string().optional(),
|
|
14409
14378
|
primaryId: z34.string().optional(),
|
|
14410
|
-
actionId: z34.string().optional(),
|
|
14411
14379
|
runId: z34.string().optional(),
|
|
14412
14380
|
afterCursor: z34.string().optional(),
|
|
14413
14381
|
limit: z34.number().int().positive().max(500).optional()
|
|
@@ -14544,8 +14512,8 @@ function registerEventStreamRoutes(app, server) {
|
|
|
14544
14512
|
});
|
|
14545
14513
|
}
|
|
14546
14514
|
function eventMatchesScope(event, filter) {
|
|
14547
|
-
const { objectTypeId, primaryId,
|
|
14548
|
-
if (objectTypeId === undefined && primaryId === undefined &&
|
|
14515
|
+
const { objectTypeId, primaryId, runId } = filter;
|
|
14516
|
+
if (objectTypeId === undefined && primaryId === undefined && runId === undefined) {
|
|
14549
14517
|
return true;
|
|
14550
14518
|
}
|
|
14551
14519
|
const scope = scopeKeysForEvent(event);
|
|
@@ -14555,9 +14523,6 @@ function eventMatchesScope(event, filter) {
|
|
|
14555
14523
|
if (primaryId !== undefined && scope.primaryId !== primaryId) {
|
|
14556
14524
|
return false;
|
|
14557
14525
|
}
|
|
14558
|
-
if (actionId !== undefined && scope.actionId !== actionId) {
|
|
14559
|
-
return false;
|
|
14560
|
-
}
|
|
14561
14526
|
if (runId !== undefined && scope.runId !== runId) {
|
|
14562
14527
|
return false;
|
|
14563
14528
|
}
|
|
@@ -14720,6 +14685,7 @@ function registerWebSocketRoutes(app, server) {
|
|
|
14720
14685
|
}
|
|
14721
14686
|
|
|
14722
14687
|
// src/server.ts
|
|
14688
|
+
var MAX_WEBSOCKET_MESSAGE_BYTES = 64 * 1024;
|
|
14723
14689
|
function createSixbServer(options) {
|
|
14724
14690
|
return new SixbServer(options);
|
|
14725
14691
|
}
|
|
@@ -14863,6 +14829,12 @@ function createSixbApi(server) {
|
|
|
14863
14829
|
}
|
|
14864
14830
|
return shared.kind === "deny" ? shared.response : undefined;
|
|
14865
14831
|
});
|
|
14832
|
+
app.onError(({ error, set }) => {
|
|
14833
|
+
if (error instanceof ParseError && error.cause instanceof RequestBodyTooLargeError) {
|
|
14834
|
+
set.status = 413;
|
|
14835
|
+
return { error: error.cause.message };
|
|
14836
|
+
}
|
|
14837
|
+
});
|
|
14866
14838
|
app.derive(async ({ request }) => {
|
|
14867
14839
|
const shared = preparedSharedAccess.get(request) ?? await sharedAccess.resolveRequest(request);
|
|
14868
14840
|
preparedSharedAccess.delete(request);
|
|
@@ -15068,8 +15040,10 @@ function startApiServer(app, options) {
|
|
|
15068
15040
|
const bunServer = Bun.serve({
|
|
15069
15041
|
port: options.port,
|
|
15070
15042
|
hostname: options.host,
|
|
15071
|
-
|
|
15072
|
-
|
|
15043
|
+
maxRequestBodySize: DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES,
|
|
15044
|
+
fetch: (incoming, server) => {
|
|
15045
|
+
const socketAddress = server.requestIP(incoming)?.address;
|
|
15046
|
+
const request = limitRequestBody(incoming);
|
|
15073
15047
|
if (socketAddress) {
|
|
15074
15048
|
const forwardedFor = request.headers.get("x-forwarded-for");
|
|
15075
15049
|
setRequestClientAddress(request, options.resolveClientAddress(socketAddress, forwardedFor));
|
|
@@ -15085,7 +15059,8 @@ function getElysiaWsHandler(app) {
|
|
|
15085
15059
|
const cfg = app.config;
|
|
15086
15060
|
return {
|
|
15087
15061
|
...elysiaWebSocket,
|
|
15088
|
-
...cfg?.websocket ?? {}
|
|
15062
|
+
...cfg?.websocket ?? {},
|
|
15063
|
+
maxPayloadLength: MAX_WEBSOCKET_MESSAGE_BYTES
|
|
15089
15064
|
};
|
|
15090
15065
|
}
|
|
15091
15066
|
function attachBunServer(app, bunServer) {
|
|
@@ -15096,4 +15071,4 @@ export {
|
|
|
15096
15071
|
createSixbServer
|
|
15097
15072
|
};
|
|
15098
15073
|
|
|
15099
|
-
//# debugId=
|
|
15074
|
+
//# debugId=AA8B124AF8294E7E64756E2164756E21
|