@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/server.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Elysia } from "elysia";
|
|
|
3
3
|
import { type AuthInvitationDestinationOptions, type AuthInvitationRedirectContext, type AuthInvitationRedirectInput, type RequestAuthContext, type ResolveAuthRedirectContext, type ResolvedSixbApiBrowserPolicy, type SixbApiBrowserPolicy } from "./auth/browser-origin";
|
|
4
4
|
import type { SixbAuthExperienceOptions } from "./auth/experience";
|
|
5
5
|
import { type SixbSharedAccessOptions } from "./auth/shared-access";
|
|
6
|
+
export declare const MAX_WEBSOCKET_MESSAGE_BYTES: number;
|
|
6
7
|
export interface SixbServerOptions {
|
|
7
8
|
host: SixbHostView;
|
|
8
9
|
port?: number;
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA6B,YAAY,EAAE,MAAM,YAAY,CAAA;AAKzE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA6B,YAAY,EAAE,MAAM,YAAY,CAAA;AAKzE,OAAO,EAAE,MAAM,EAAc,MAAM,QAAQ,CAAA;AAG3C,OAAO,EACL,KAAK,gCAAgC,EACrC,KAAK,6BAA6B,EAClC,KAAK,2BAA2B,EAMhC,KAAK,kBAAkB,EACvB,KAAK,0BAA0B,EAC/B,KAAK,4BAA4B,EAKjC,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAA;AAO9B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAA;AAKlE,OAAO,EAGL,KAAK,uBAAuB,EAC7B,MAAM,sBAAsB,CAAA;AAuB7B,eAAO,MAAM,2BAA2B,QAAY,CAAA;AAEpD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,YAAY,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,OAAO,EAAE,oBAAoB,CAAA;IAC7B,8EAA8E;IAC9E,cAAc,CAAC,EAAE,yBAAyB,CAAA;IAC1C,qEAAqE;IACrE,YAAY,CAAC,EAAE,uBAAuB,CAAA;IACtC;;;OAGG;IACH,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CACnC;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,UAAU,CAEvE;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAQ;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;IACjC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA8B;IAC/D,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAA2B;IAC/D,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAA4B;IACxE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAA2B;IAC3D,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAyB;IAC7D,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAuB;IAC5D,OAAO,CAAC,GAAG,CAAuB;IAClC,OAAO,CAAC,SAAS,CAA4C;IAC7D,OAAO,CAAC,WAAW,CAAyC;gBAEhD,OAAO,EAAE,iBAAiB;IAqBtC,OAAO,IAAI,YAAY;IAIvB,OAAO,IAAI,MAAM;IAIjB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,kBAAkB;IAIxD,0BAA0B,CACxB,OAAO,EAAE,UAAU,CAAC,0BAA0B,CAAC,CAAC,CAAC,CAAC,EAClD,KAAK,EAAE,UAAU,CAAC,0BAA0B,CAAC,CAAC,CAAC,CAAC,GAC/C,UAAU,CAAC,0BAA0B,CAAC;IAIzC,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM;IAIlD,+BAA+B,CAAC,QAAQ,EAAE,OAAO,GAAG,gCAAgC;IAIpF,gCAAgC,CAC9B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,2BAA2B,GACjC,6BAA6B;IAIhC,mBAAmB,IAAI,4BAA4B;IAInD,iBAAiB,IAAI,yBAAyB,GAAG,SAAS;IAI1D,sBAAsB,IAAI,uBAAuB;IAI3C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA+BtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAe5B;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyP/C;AAiED,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAA"}
|
package/dist/utils/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/utils/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,iBAAiB,EACtB,KAAK,aAAa,EACnB,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/utils/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,iBAAiB,EACtB,KAAK,aAAa,EACnB,MAAM,YAAY,CAAA;AA+BnB,UAAU,gBAAgB;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,CAE/C;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,CAWrE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAW9E;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CACzC,GAAG,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACjC,IAAI,EAAE,MAAM,GACX;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAGnB;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,gBAAgB,GACpB;IACD,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,aAAa,CAAA;IACpB,OAAO,CAAC,EAAE,iBAAiB,CAAA;CAC5B,CA6CA"}
|
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Request body limits for the API.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Elysia parses a JSON or form body before the auth guard runs, so the server caps every body it
|
|
5
|
+
* receives at `DEFAULT_REQUEST_BODY_LIMIT_BYTES` (`limitRequestBody`). A route that takes more,
|
|
6
|
+
* such as a file upload, reads its own body with `readRequestBodyWithLimit`, whose limit replaces
|
|
7
|
+
* that cap. Both apply the limit DURING streaming (not after buffering), so an oversized or
|
|
8
|
+
* chunked/unknown-length body is rejected before it is fully read.
|
|
8
9
|
*/
|
|
10
|
+
/** The most a request body may be, unless the route reading it allows more. */
|
|
11
|
+
export declare const DEFAULT_REQUEST_BODY_LIMIT_BYTES: number;
|
|
9
12
|
export declare class RequestBodyTooLargeError extends Error {
|
|
10
13
|
readonly limitBytes: number;
|
|
11
14
|
readonly name = "RequestBodyTooLargeError";
|
|
12
15
|
constructor(limitBytes: number, message?: string);
|
|
13
16
|
}
|
|
14
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Returns `request` with its body capped at `DEFAULT_REQUEST_BODY_LIMIT_BYTES`. Reading past the
|
|
19
|
+
* cap fails with `RequestBodyTooLargeError`, which Elysia surfaces as a parse error.
|
|
20
|
+
*/
|
|
21
|
+
export declare function limitRequestBody(request: Request): Request;
|
|
22
|
+
/**
|
|
23
|
+
* Reads a request body fully into memory, failing once it passes `limitBytes`. That limit
|
|
24
|
+
* replaces the server's default cap for this request, so a route reading more than the default
|
|
25
|
+
* must authenticate the caller first. The `content-length` header, when present, only provides an
|
|
26
|
+
* early fast-path.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readRequestBodyWithLimit(request: Request, limitBytes: number, tooLargeMessage?: string): Promise<Uint8Array<ArrayBuffer>>;
|
|
15
29
|
//# sourceMappingURL=request-body.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-body.d.ts","sourceRoot":"","sources":["../../src/utils/request-body.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"request-body.d.ts","sourceRoot":"","sources":["../../src/utils/request-body.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,+EAA+E;AAC/E,eAAO,MAAM,gCAAgC,QAAc,CAAA;AAE3D,qBAAa,wBAAyB,SAAQ,KAAK;IAI/C,QAAQ,CAAC,UAAU,EAAE,MAAM;IAH7B,QAAQ,CAAC,IAAI,8BAA6B;gBAG/B,UAAU,EAAE,MAAM,EAC3B,OAAO,SAAuD;CAIjE;AAID;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAwB1D;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,MAAM,EAClB,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CA4ClC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sixb/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.19",
|
|
4
4
|
"description": "HTTP and WebSocket API server for Sixb",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sixb",
|
|
@@ -38,14 +38,14 @@
|
|
|
38
38
|
"zod-to-json-schema": "^3.24.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@sixb/core": "0.1.
|
|
41
|
+
"@sixb/core": "0.1.19"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@sixb/auth-magic-link": "0.1.5",
|
|
45
45
|
"@sixb/auth-oidc": "0.1.5",
|
|
46
|
-
"@sixb/cli-core": "0.1.
|
|
47
|
-
"@sixb/core": "0.1.
|
|
48
|
-
"@sixb/sqlite": "0.1.
|
|
46
|
+
"@sixb/cli-core": "0.1.8",
|
|
47
|
+
"@sixb/core": "0.1.19",
|
|
48
|
+
"@sixb/sqlite": "0.1.19",
|
|
49
49
|
"@types/bun": "latest",
|
|
50
50
|
"typescript": "^5.7.0"
|
|
51
51
|
},
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ActionRunRecord } from "@sixb/core/storage"
|
|
2
|
+
import { ActionRunDetailSchema, ActionRunSummarySchema } from "../schemas/actions"
|
|
3
|
+
import { toIsoString } from "../utils/http"
|
|
4
|
+
|
|
5
|
+
/** The run summary run listings answer with. */
|
|
6
|
+
export function serializeActionRunSummary(
|
|
7
|
+
run: ActionRunRecord
|
|
8
|
+
): ReturnType<typeof ActionRunSummarySchema.parse> {
|
|
9
|
+
return ActionRunSummarySchema.parse({
|
|
10
|
+
id: run.id,
|
|
11
|
+
projectId: run.projectId,
|
|
12
|
+
actionId: run.actionId,
|
|
13
|
+
subject: run.subject,
|
|
14
|
+
status: run.status,
|
|
15
|
+
phase: run.phase,
|
|
16
|
+
startedAt: toIsoString(run.startedAt),
|
|
17
|
+
finishedAt: toIsoString(run.finishedAt),
|
|
18
|
+
error: run.error,
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The run detail every route that returns one run answers with. */
|
|
23
|
+
export function serializeActionRunDetail(
|
|
24
|
+
run: ActionRunRecord
|
|
25
|
+
): ReturnType<typeof ActionRunDetailSchema.parse> {
|
|
26
|
+
return ActionRunDetailSchema.parse({
|
|
27
|
+
...serializeActionRunSummary(run),
|
|
28
|
+
params: run.params,
|
|
29
|
+
writeback: run.writeback
|
|
30
|
+
? run.writeback.status === "succeeded"
|
|
31
|
+
? {
|
|
32
|
+
status: "succeeded",
|
|
33
|
+
completedAt: toIsoString(run.writeback.completedAt),
|
|
34
|
+
result: run.writeback.result,
|
|
35
|
+
}
|
|
36
|
+
: {
|
|
37
|
+
status: "failed",
|
|
38
|
+
completedAt: toIsoString(run.writeback.completedAt),
|
|
39
|
+
error: run.writeback.error,
|
|
40
|
+
}
|
|
41
|
+
: undefined,
|
|
42
|
+
effects: run.effects
|
|
43
|
+
? run.effects.status === "succeeded"
|
|
44
|
+
? {
|
|
45
|
+
status: "succeeded",
|
|
46
|
+
completedAt: toIsoString(run.effects.completedAt),
|
|
47
|
+
}
|
|
48
|
+
: {
|
|
49
|
+
status: "failed",
|
|
50
|
+
completedAt: toIsoString(run.effects.completedAt),
|
|
51
|
+
error: run.effects.error,
|
|
52
|
+
}
|
|
53
|
+
: undefined,
|
|
54
|
+
})
|
|
55
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SixbHostView } from "@sixb/core"
|
|
2
|
-
import type { ActionRunRecord } from "@sixb/core/storage"
|
|
3
2
|
import type { Elysia } from "elysia"
|
|
4
3
|
import { z } from "zod"
|
|
4
|
+
import { serializeActionRunDetail, serializeActionRunSummary } from "../actions/serialize"
|
|
5
5
|
import { accessTokenSecurityRequirement } from "../auth/access-token-boundary"
|
|
6
6
|
import { requireRequestSixb } from "../auth/scope"
|
|
7
7
|
import {
|
|
@@ -15,7 +15,6 @@ import {
|
|
|
15
15
|
ActionRunDetailSchema,
|
|
16
16
|
ActionRunIdParamsSchema,
|
|
17
17
|
ActionRunListResponseSchema,
|
|
18
|
-
ActionRunSummarySchema,
|
|
19
18
|
ActionRunsQuerySchema,
|
|
20
19
|
} from "../schemas/actions"
|
|
21
20
|
import { ErrorResponseSchema } from "../schemas/common"
|
|
@@ -24,7 +23,6 @@ import {
|
|
|
24
23
|
handleRouteError,
|
|
25
24
|
parseDate,
|
|
26
25
|
parseOptionalInt,
|
|
27
|
-
toIsoString,
|
|
28
26
|
unconfiguredStorageResponse,
|
|
29
27
|
} from "../utils/http"
|
|
30
28
|
|
|
@@ -38,57 +36,6 @@ const ActionRunFileContentQuerySchema = FileContentQuerySchema.extend({
|
|
|
38
36
|
),
|
|
39
37
|
})
|
|
40
38
|
|
|
41
|
-
function serializeActionRunSummary(
|
|
42
|
-
run: ActionRunRecord
|
|
43
|
-
): ReturnType<typeof ActionRunSummarySchema.parse> {
|
|
44
|
-
return ActionRunSummarySchema.parse({
|
|
45
|
-
id: run.id,
|
|
46
|
-
projectId: run.projectId,
|
|
47
|
-
actionId: run.actionId,
|
|
48
|
-
subject: run.subject,
|
|
49
|
-
status: run.status,
|
|
50
|
-
phase: run.phase,
|
|
51
|
-
queuedAt: toIsoString(run.queuedAt),
|
|
52
|
-
startedAt: run.startedAt ? toIsoString(run.startedAt) : undefined,
|
|
53
|
-
finishedAt: run.finishedAt ? toIsoString(run.finishedAt) : undefined,
|
|
54
|
-
error: run.error,
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function serializeActionRunDetail(
|
|
59
|
-
run: ActionRunRecord
|
|
60
|
-
): ReturnType<typeof ActionRunDetailSchema.parse> {
|
|
61
|
-
return ActionRunDetailSchema.parse({
|
|
62
|
-
...serializeActionRunSummary(run),
|
|
63
|
-
params: run.params,
|
|
64
|
-
writeback: run.writeback
|
|
65
|
-
? run.writeback.status === "succeeded"
|
|
66
|
-
? {
|
|
67
|
-
status: "succeeded",
|
|
68
|
-
completedAt: toIsoString(run.writeback.completedAt),
|
|
69
|
-
result: run.writeback.result,
|
|
70
|
-
}
|
|
71
|
-
: {
|
|
72
|
-
status: "failed",
|
|
73
|
-
completedAt: toIsoString(run.writeback.completedAt),
|
|
74
|
-
error: run.writeback.error,
|
|
75
|
-
}
|
|
76
|
-
: undefined,
|
|
77
|
-
effects: run.effects
|
|
78
|
-
? run.effects.status === "succeeded"
|
|
79
|
-
? {
|
|
80
|
-
status: "succeeded",
|
|
81
|
-
completedAt: toIsoString(run.effects.completedAt),
|
|
82
|
-
}
|
|
83
|
-
: {
|
|
84
|
-
status: "failed",
|
|
85
|
-
completedAt: toIsoString(run.effects.completedAt),
|
|
86
|
-
error: run.effects.error,
|
|
87
|
-
}
|
|
88
|
-
: undefined,
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
|
|
92
39
|
async function actionRunFileContentResponse(
|
|
93
40
|
host: SixbHostView,
|
|
94
41
|
context: {
|
package/src/routes/actions.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ActionDescriptor, SixbHostView } from "@sixb/core"
|
|
2
2
|
import { schemaFieldsToJsonSchema } from "@sixb/core/internal/ontology"
|
|
3
3
|
import type { Elysia } from "elysia"
|
|
4
|
+
import { serializeActionRunDetail } from "../actions/serialize"
|
|
4
5
|
import { accessTokenSecurityRequirement } from "../auth/access-token-boundary"
|
|
5
6
|
import { requireRequestSixb } from "../auth/scope"
|
|
6
7
|
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
@@ -8,8 +9,11 @@ import {
|
|
|
8
9
|
ActionCatalogItemSchema,
|
|
9
10
|
ActionDetailSchema,
|
|
10
11
|
ActionIdParamsSchema,
|
|
12
|
+
ActionRequestFailedResponseSchema,
|
|
13
|
+
ActionRunDetailSchema,
|
|
14
|
+
ActionRunInProgressResponseSchema,
|
|
11
15
|
RequestActionBodySchema,
|
|
12
|
-
|
|
16
|
+
RuntimeStoppingResponseSchema,
|
|
13
17
|
} from "../schemas/actions"
|
|
14
18
|
import { ErrorResponseSchema } from "../schemas/common"
|
|
15
19
|
import { handleRouteError } from "../utils/http"
|
|
@@ -92,20 +96,24 @@ export function registerActionRoutes(app: Elysia, host: SixbHostView) {
|
|
|
92
96
|
.post(
|
|
93
97
|
"/api/actions/:actionId",
|
|
94
98
|
async (context) => {
|
|
95
|
-
const { params, body, set } = context
|
|
99
|
+
const { params, body, set, request, server } = context
|
|
100
|
+
// An Action can outlast Bun's 10-second idle timeout: it has 30 seconds to reach its
|
|
101
|
+
// boundary, then edits that nothing interrupts, then up to 30 seconds of effects.
|
|
102
|
+
server?.timeout(request, 0)
|
|
103
|
+
|
|
96
104
|
const sixb = requireRequestSixb(context)
|
|
97
105
|
try {
|
|
98
106
|
const parsedBody = RequestActionBodySchema.parse(body)
|
|
99
|
-
|
|
107
|
+
// No `request.signal`: a client that disconnects never cancels the run. Retrying with
|
|
108
|
+
// the same `runId` returns its record once it is terminal.
|
|
109
|
+
const run = await sixb.actions.request({
|
|
100
110
|
actionId: params.actionId,
|
|
101
111
|
subject: parsedBody.subject,
|
|
102
112
|
params: parsedBody.params,
|
|
103
113
|
runId: parsedBody.runId,
|
|
104
|
-
}
|
|
105
|
-
const result = await sixb.actions.request(input)
|
|
114
|
+
})
|
|
106
115
|
|
|
107
|
-
|
|
108
|
-
return RequestActionResponseSchema.parse(result)
|
|
116
|
+
return serializeActionRunDetail(run)
|
|
109
117
|
} catch (error) {
|
|
110
118
|
return handleRouteError(error, set)
|
|
111
119
|
}
|
|
@@ -114,13 +122,23 @@ export function registerActionRoutes(app: Elysia, host: SixbHostView) {
|
|
|
114
122
|
params: ActionIdParamsSchema,
|
|
115
123
|
body: RequestActionBodySchema,
|
|
116
124
|
response: {
|
|
117
|
-
|
|
125
|
+
200: ActionRunDetailSchema,
|
|
118
126
|
400: ErrorResponseSchema,
|
|
119
127
|
403: ErrorResponseSchema,
|
|
120
128
|
404: ErrorResponseSchema,
|
|
129
|
+
409: ActionRunInProgressResponseSchema,
|
|
130
|
+
500: ActionRequestFailedResponseSchema,
|
|
131
|
+
503: RuntimeStoppingResponseSchema,
|
|
121
132
|
},
|
|
122
133
|
detail: {
|
|
123
134
|
summary: "Request an action",
|
|
135
|
+
description:
|
|
136
|
+
"Runs the action and returns its terminal run. A run that fails is returned with " +
|
|
137
|
+
"status `failed`. Its effects run after the response, which does not wait for them. " +
|
|
138
|
+
"An error response usually means no run was requested, but a 500 can follow a run " +
|
|
139
|
+
"that started: request again with the same `runId` to get its record if it was " +
|
|
140
|
+
"written. A `runId` that was already recorded returns that run, and 409 while this " +
|
|
141
|
+
"server still runs it. 503 means the server is stopping and started nothing.",
|
|
124
142
|
tags: [OPENAPI_TAGS.actions.name],
|
|
125
143
|
operationId: "requestAction",
|
|
126
144
|
security: accessTokenSecurityRequirement("requestAction"),
|
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
} from "@sixb/core/storage"
|
|
21
21
|
import type { Elysia } from "elysia"
|
|
22
22
|
import { type InternalRequestAuthState, registerInternalRequestAuthState } from "../auth/scope"
|
|
23
|
+
import { RequestBodyTooLargeError, readRequestBodyWithLimit } from "../utils/request-body"
|
|
23
24
|
import { DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES } from "./files"
|
|
24
25
|
|
|
25
26
|
const MAX_AGENT_API_BODY_BYTES = 1_000_000
|
|
@@ -100,16 +101,11 @@ async function handleAgentApiGatewayRequest(input: {
|
|
|
100
101
|
)
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
let body: ArrayBuffer | undefined
|
|
104
|
+
let body: Uint8Array<ArrayBuffer> | undefined
|
|
104
105
|
try {
|
|
105
|
-
body = await
|
|
106
|
-
input.request,
|
|
107
|
-
isSimpleFileUpload(input.request.method, upstreamPath)
|
|
108
|
-
? DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES
|
|
109
|
-
: MAX_AGENT_API_BODY_BYTES
|
|
110
|
-
)
|
|
106
|
+
body = await readGatewayRequestBody(input.request, upstreamPath)
|
|
111
107
|
} catch (error) {
|
|
112
|
-
if (error instanceof
|
|
108
|
+
if (error instanceof RequestBodyTooLargeError) {
|
|
113
109
|
return jsonError(413, error.message)
|
|
114
110
|
}
|
|
115
111
|
throw error
|
|
@@ -343,33 +339,26 @@ function copyHeader(source: Headers, target: Headers, name: string): void {
|
|
|
343
339
|
}
|
|
344
340
|
}
|
|
345
341
|
|
|
346
|
-
async function
|
|
342
|
+
async function readGatewayRequestBody(
|
|
347
343
|
request: Request,
|
|
348
|
-
|
|
349
|
-
): Promise<ArrayBuffer | undefined> {
|
|
344
|
+
upstreamPath: string
|
|
345
|
+
): Promise<Uint8Array<ArrayBuffer> | undefined> {
|
|
350
346
|
if (!request.body || request.method === "GET" || request.method === "HEAD") {
|
|
351
347
|
return undefined
|
|
352
348
|
}
|
|
353
349
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
if (done) break
|
|
361
|
-
total += value.byteLength
|
|
362
|
-
if (total > maxBytes) {
|
|
363
|
-
throw new PayloadTooLargeError(
|
|
364
|
-
maxBytes === MAX_AGENT_API_BODY_BYTES
|
|
365
|
-
? "Agent API gateway request body exceeds 1MB."
|
|
366
|
-
: `Agent API gateway file upload request body exceeds the ${maxBytes} byte limit.`
|
|
367
|
-
)
|
|
368
|
-
}
|
|
369
|
-
chunks.push(value)
|
|
350
|
+
if (isSimpleFileUpload(request.method, upstreamPath)) {
|
|
351
|
+
return readRequestBodyWithLimit(
|
|
352
|
+
request,
|
|
353
|
+
DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES,
|
|
354
|
+
`Agent API gateway file upload request body exceeds the ${DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES} byte limit.`
|
|
355
|
+
)
|
|
370
356
|
}
|
|
371
|
-
|
|
372
|
-
|
|
357
|
+
return readRequestBodyWithLimit(
|
|
358
|
+
request,
|
|
359
|
+
MAX_AGENT_API_BODY_BYTES,
|
|
360
|
+
"Agent API gateway request body exceeds 1MB."
|
|
361
|
+
)
|
|
373
362
|
}
|
|
374
363
|
|
|
375
364
|
function isSimpleFileUpload(method: string, pathname: string): boolean {
|
|
@@ -386,19 +375,6 @@ function matchesWorkflowRunStart(pathname: string): boolean {
|
|
|
386
375
|
)
|
|
387
376
|
}
|
|
388
377
|
|
|
389
|
-
function concatChunks(chunks: readonly Uint8Array[], total: number): ArrayBuffer {
|
|
390
|
-
const buffer = new ArrayBuffer(total)
|
|
391
|
-
const result = new Uint8Array(buffer)
|
|
392
|
-
let offset = 0
|
|
393
|
-
for (const chunk of chunks) {
|
|
394
|
-
result.set(chunk, offset)
|
|
395
|
-
offset += chunk.byteLength
|
|
396
|
-
}
|
|
397
|
-
return buffer
|
|
398
|
-
}
|
|
399
|
-
|
|
400
378
|
function jsonError(status: number, message: string): Response {
|
|
401
379
|
return Response.json({ error: message }, { status })
|
|
402
380
|
}
|
|
403
|
-
|
|
404
|
-
class PayloadTooLargeError extends Error {}
|
package/src/routes/files.ts
CHANGED
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
SignedFileUploadPartSchema,
|
|
26
26
|
} from "../schemas/files"
|
|
27
27
|
import { handleRouteError, unconfiguredStorageResponse } from "../utils/http"
|
|
28
|
-
import {
|
|
28
|
+
import { readRequestBodyWithLimit } from "../utils/request-body"
|
|
29
29
|
// The simple-upload ceiling lives in @sixb/core so the client staged-switch
|
|
30
30
|
// threshold and this server limit stay a single source of truth. The body limit
|
|
31
31
|
// adds headroom for multipart/form-data encoding overhead on the `POST /api/files`
|
|
@@ -40,16 +40,14 @@ export function registerFileRoutes(app: Elysia, host: SixbHostView) {
|
|
|
40
40
|
"/api/files",
|
|
41
41
|
async ({ request, set }) => {
|
|
42
42
|
try {
|
|
43
|
-
const
|
|
43
|
+
const bytes = await readRequestBodyWithLimit(
|
|
44
44
|
request,
|
|
45
|
-
DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES
|
|
45
|
+
DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES,
|
|
46
|
+
`File upload request exceeds the ${DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES} byte limit.`
|
|
46
47
|
)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const form = await request.formData()
|
|
48
|
+
const form = await new Response(bytes, {
|
|
49
|
+
headers: { "content-type": request.headers.get("content-type") ?? "" },
|
|
50
|
+
}).formData()
|
|
53
51
|
const file = form.get("file")
|
|
54
52
|
const logicalPath = form.get("logicalPath")
|
|
55
53
|
|
|
@@ -205,7 +203,10 @@ export function registerFileRoutes(app: Elysia, host: SixbHostView) {
|
|
|
205
203
|
return { error: contentLengthSizeError }
|
|
206
204
|
}
|
|
207
205
|
|
|
208
|
-
const uploadBytes =
|
|
206
|
+
const uploadBytes = await readRequestBodyWithLimit(
|
|
207
|
+
request,
|
|
208
|
+
DEFAULT_SIMPLE_FILE_UPLOAD_BYTES
|
|
209
|
+
)
|
|
209
210
|
if (uploadBytes.byteLength === 0) {
|
|
210
211
|
set.status = 400
|
|
211
212
|
return { error: "Expected upload content body." }
|
|
@@ -239,18 +240,16 @@ export function registerFileRoutes(app: Elysia, host: SixbHostView) {
|
|
|
239
240
|
},
|
|
240
241
|
{
|
|
241
242
|
params: FileUploadIdParamsSchema,
|
|
242
|
-
//
|
|
243
|
-
//
|
|
244
|
-
parse:
|
|
245
|
-
// The cap is enforced during parsing, which is outside the handler's
|
|
246
|
-
// try/catch, so map its too-large error to 413 here.
|
|
247
|
-
error: mapUploadContentError,
|
|
243
|
+
// The handler reads the content itself, once it knows the caller and the session, so
|
|
244
|
+
// Elysia must not parse the body first.
|
|
245
|
+
parse: "none",
|
|
248
246
|
response: {
|
|
249
247
|
200: SuccessResponseSchema,
|
|
250
248
|
400: ErrorResponseSchema,
|
|
251
249
|
404: ErrorResponseSchema,
|
|
252
250
|
409: ErrorResponseSchema,
|
|
253
251
|
410: ErrorResponseSchema,
|
|
252
|
+
413: ErrorResponseSchema,
|
|
254
253
|
501: ErrorResponseSchema,
|
|
255
254
|
},
|
|
256
255
|
detail: {
|
|
@@ -498,39 +497,6 @@ function fileUploadResponse(session: FileUploadSession) {
|
|
|
498
497
|
}
|
|
499
498
|
}
|
|
500
499
|
|
|
501
|
-
// Elysia `parse` hook: reads the staged content stream with a hard size ceiling,
|
|
502
|
-
// so an oversized (or chunked, content-length-lying) body is rejected before it
|
|
503
|
-
// is fully buffered. Its result becomes `context.body`.
|
|
504
|
-
function readCappedUploadBody(context: { request: Request }): Promise<Uint8Array> {
|
|
505
|
-
return readRequestBodyWithLimit(context.request, DEFAULT_SIMPLE_FILE_UPLOAD_BYTES)
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
function readParsedUploadBytes(context: { body?: unknown }): Uint8Array {
|
|
509
|
-
return context.body instanceof Uint8Array ? context.body : new Uint8Array(0)
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
function mapUploadContentError(context: {
|
|
513
|
-
error: unknown
|
|
514
|
-
set: { status?: number | string }
|
|
515
|
-
}): { error: string } | undefined {
|
|
516
|
-
const tooLarge = asRequestBodyTooLarge(context.error)
|
|
517
|
-
if (tooLarge) {
|
|
518
|
-
context.set.status = 413
|
|
519
|
-
return { error: tooLarge.message }
|
|
520
|
-
}
|
|
521
|
-
return undefined
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
// The cap runs in the `parse` phase, so Elysia surfaces it wrapped in a
|
|
525
|
-
// ParseError; the original error is carried on `cause`.
|
|
526
|
-
function asRequestBodyTooLarge(error: unknown): RequestBodyTooLargeError | undefined {
|
|
527
|
-
if (error instanceof RequestBodyTooLargeError) {
|
|
528
|
-
return error
|
|
529
|
-
}
|
|
530
|
-
const cause = (error as { cause?: unknown } | null | undefined)?.cause
|
|
531
|
-
return cause instanceof RequestBodyTooLargeError ? cause : undefined
|
|
532
|
-
}
|
|
533
|
-
|
|
534
500
|
// A non-pending session is terminal; surface which terminal state so the route
|
|
535
501
|
// boundary maps it to 409. Store lookups already raise `not_found`/`expired`.
|
|
536
502
|
function terminalSessionError(status: "completed" | "aborted"): FileUploadSessionError {
|
|
@@ -649,20 +615,6 @@ function expectedSizeBytesValueError(
|
|
|
649
615
|
: null
|
|
650
616
|
}
|
|
651
617
|
|
|
652
|
-
function requestSizeLimitError(request: Request, maxSizeBytes: number): string | null {
|
|
653
|
-
const value = request.headers.get("content-length")
|
|
654
|
-
if (value === null) {
|
|
655
|
-
return null
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
const sizeBytes = Number(value)
|
|
659
|
-
if (!Number.isSafeInteger(sizeBytes) || sizeBytes <= maxSizeBytes) {
|
|
660
|
-
return null
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
return `File upload request exceeds the ${maxSizeBytes} byte limit.`
|
|
664
|
-
}
|
|
665
|
-
|
|
666
618
|
function expectedContentLengthError(session: FileUploadSession, request: Request): string | null {
|
|
667
619
|
if (session.expectedSizeBytes === undefined) {
|
|
668
620
|
return null
|
package/src/routes/ws/events.ts
CHANGED
|
@@ -23,7 +23,6 @@ const SubscribeSchema = z.object({
|
|
|
23
23
|
types: z.array(z.enum(EVENT_TYPES)).optional(),
|
|
24
24
|
objectTypeId: z.string().optional(),
|
|
25
25
|
primaryId: z.string().optional(),
|
|
26
|
-
actionId: z.string().optional(),
|
|
27
26
|
runId: z.string().optional(),
|
|
28
27
|
afterCursor: z.string().optional(),
|
|
29
28
|
limit: z.number().int().positive().max(500).optional(),
|
|
@@ -212,17 +211,11 @@ function eventMatchesScope(
|
|
|
212
211
|
filter: {
|
|
213
212
|
readonly objectTypeId?: string
|
|
214
213
|
readonly primaryId?: string
|
|
215
|
-
readonly actionId?: string
|
|
216
214
|
readonly runId?: string
|
|
217
215
|
}
|
|
218
216
|
): boolean {
|
|
219
|
-
const { objectTypeId, primaryId,
|
|
220
|
-
if (
|
|
221
|
-
objectTypeId === undefined &&
|
|
222
|
-
primaryId === undefined &&
|
|
223
|
-
actionId === undefined &&
|
|
224
|
-
runId === undefined
|
|
225
|
-
) {
|
|
217
|
+
const { objectTypeId, primaryId, runId } = filter
|
|
218
|
+
if (objectTypeId === undefined && primaryId === undefined && runId === undefined) {
|
|
226
219
|
return true
|
|
227
220
|
}
|
|
228
221
|
|
|
@@ -233,9 +226,6 @@ function eventMatchesScope(
|
|
|
233
226
|
if (primaryId !== undefined && scope.primaryId !== primaryId) {
|
|
234
227
|
return false
|
|
235
228
|
}
|
|
236
|
-
if (actionId !== undefined && scope.actionId !== actionId) {
|
|
237
|
-
return false
|
|
238
|
-
}
|
|
239
229
|
if (runId !== undefined && scope.runId !== runId) {
|
|
240
230
|
return false
|
|
241
231
|
}
|
package/src/schemas/actions.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { SIXB_ERROR_CODES } from "@sixb/core/internal/errors"
|
|
1
2
|
import {
|
|
2
3
|
ACTION_RUN_FAILURE_CODES,
|
|
3
4
|
ACTION_RUN_PHASES,
|
|
4
5
|
type ActionRunFailure,
|
|
5
6
|
} from "@sixb/core/storage"
|
|
6
7
|
import { z } from "zod"
|
|
7
|
-
import { JsonValueSchema, sixbFailureSchema } from "./common"
|
|
8
|
+
import { codedErrorResponseSchema, JsonValueSchema, sixbFailureSchema } from "./common"
|
|
8
9
|
import { ActionParamSchema } from "./ontology"
|
|
9
10
|
|
|
10
11
|
export const ActionIdParamsSchema = z.object({
|
|
@@ -32,12 +33,19 @@ export const RequestActionBodySchema = z.object({
|
|
|
32
33
|
runId: z.string().min(1).optional(),
|
|
33
34
|
})
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
/** A request reused the run id of a run this server is still executing. */
|
|
37
|
+
export const ActionRunInProgressResponseSchema = codedErrorResponseSchema([
|
|
38
|
+
"action.run_in_progress",
|
|
39
|
+
])
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* An unexpected failure. It can follow a run that started: requesting the same `runId` again
|
|
43
|
+
* returns the run's record if it was written, and runs it again otherwise.
|
|
44
|
+
*/
|
|
45
|
+
export const ActionRequestFailedResponseSchema = codedErrorResponseSchema(SIXB_ERROR_CODES)
|
|
46
|
+
|
|
47
|
+
/** The server is stopping and refused the request before starting anything. */
|
|
48
|
+
export const RuntimeStoppingResponseSchema = codedErrorResponseSchema(["runtime.stopping"])
|
|
41
49
|
|
|
42
50
|
export const ActionCatalogItemSchema = z.object({
|
|
43
51
|
id: z.string(),
|
|
@@ -58,13 +66,8 @@ export const ActionDetailSchema = ActionCatalogItemSchema.extend({
|
|
|
58
66
|
inputSchema: z.record(z.unknown()),
|
|
59
67
|
})
|
|
60
68
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"running",
|
|
64
|
-
"succeeded",
|
|
65
|
-
"failed",
|
|
66
|
-
"cancelled",
|
|
67
|
-
])
|
|
69
|
+
/** How a run ended: a run is recorded once, when it ends. */
|
|
70
|
+
export const ActionRunStatusSchema = z.enum(["succeeded", "failed"])
|
|
68
71
|
|
|
69
72
|
export const ActionRunPhaseSchema = z.enum(ACTION_RUN_PHASES)
|
|
70
73
|
|
|
@@ -116,10 +119,10 @@ export const ActionRunSummarySchema = z.object({
|
|
|
116
119
|
actionId: z.string(),
|
|
117
120
|
subject: ActionSubjectSchema,
|
|
118
121
|
status: ActionRunStatusSchema,
|
|
119
|
-
phase
|
|
120
|
-
|
|
121
|
-
startedAt: z.string()
|
|
122
|
-
finishedAt: z.string()
|
|
122
|
+
/** The last phase the run reached. */
|
|
123
|
+
phase: ActionRunPhaseSchema,
|
|
124
|
+
startedAt: z.string(),
|
|
125
|
+
finishedAt: z.string(),
|
|
123
126
|
error: ActionRunFailureSchema.optional(),
|
|
124
127
|
})
|
|
125
128
|
|