@sixb/server 0.1.18 → 0.1.20
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 +15 -24
- package/dist/actions/serialize.d.ts +7 -0
- package/dist/actions/serialize.d.ts.map +1 -0
- package/dist/auth/browser-origin.d.ts +4 -26
- package/dist/auth/browser-origin.d.ts.map +1 -1
- package/dist/auth/experience.d.ts +0 -3
- package/dist/auth/experience.d.ts.map +1 -1
- package/dist/auth/guard.d.ts +1 -1
- package/dist/auth/guard.d.ts.map +1 -1
- package/dist/auth/public-routes.d.ts +0 -5
- package/dist/auth/public-routes.d.ts.map +1 -1
- package/dist/auth/responses.d.ts +0 -2
- package/dist/auth/responses.d.ts.map +1 -1
- package/dist/auth/session-cookies.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +681 -935
- package/dist/index.js.map +24 -24
- package/dist/routes/action-runs.d.ts +11 -15
- 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 -22
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/auth.d.ts +8 -17
- package/dist/routes/auth.d.ts.map +1 -1
- 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/objects.d.ts +0 -2
- package/dist/routes/objects.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 -52
- package/dist/routes/workflows.d.ts.map +1 -1
- 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/auth.d.ts +28 -63
- package/dist/schemas/auth.d.ts.map +1 -1
- 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 -7
- package/dist/schemas/files.d.ts.map +1 -1
- 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 +2 -2
- 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 +7 -7
- package/src/actions/serialize.ts +55 -0
- package/src/auth/browser-origin.ts +30 -240
- package/src/auth/experience.ts +1 -4
- package/src/auth/guard.ts +4 -32
- package/src/auth/public-routes.ts +1 -10
- package/src/auth/responses.ts +0 -5
- package/src/auth/session-cookies.ts +1 -3
- package/src/auth/shared-access.ts +1 -1
- package/src/index.ts +1 -1
- 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/auth.ts +32 -111
- package/src/routes/files.ts +15 -63
- package/src/routes/ws/events.ts +2 -12
- package/src/schemas/actions.ts +21 -18
- package/src/schemas/auth.ts +2 -15
- package/src/schemas/files.ts +0 -6
- package/src/server.ts +23 -18
- package/src/utils/http.ts +2 -0
- package/src/utils/request-body.ts +55 -6
- package/dist/auth/application-access.d.ts +0 -4
- package/dist/auth/application-access.d.ts.map +0 -1
- package/src/auth/application-access.ts +0 -15
|
@@ -10,11 +10,6 @@ export type RouteAccessKind = "public" | "api" | "html" | "websocket"
|
|
|
10
10
|
export interface RouteAccess {
|
|
11
11
|
readonly kind: RouteAccessKind
|
|
12
12
|
readonly csrfProtected: boolean
|
|
13
|
-
/**
|
|
14
|
-
* An instance account page every signed-in user needs, whichever web app they may open: approving
|
|
15
|
-
* a CLI login. Application access does not gate it.
|
|
16
|
-
*/
|
|
17
|
-
readonly account?: true
|
|
18
13
|
}
|
|
19
14
|
|
|
20
15
|
export function classifyRoute(request: Request): RouteAccess {
|
|
@@ -33,11 +28,7 @@ export function classifyRoute(request: Request): RouteAccess {
|
|
|
33
28
|
return { kind: "api", csrfProtected: !isCsrfExemptMethod(request.method) }
|
|
34
29
|
}
|
|
35
30
|
|
|
36
|
-
if (pathname === "/auth/device") {
|
|
37
|
-
return { kind: "html", csrfProtected: !isCsrfExemptMethod(request.method), account: true }
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (pathname === "/docs" || pathname.startsWith("/docs/")) {
|
|
31
|
+
if (pathname === "/auth/device" || pathname === "/docs" || pathname.startsWith("/docs/")) {
|
|
41
32
|
return { kind: "html", csrfProtected: !isCsrfExemptMethod(request.method) }
|
|
42
33
|
}
|
|
43
34
|
|
package/src/auth/responses.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { AuthSessionAudience } from "@sixb/core"
|
|
2
1
|
import { returnToForRequest } from "./return-to"
|
|
3
2
|
|
|
4
3
|
export function jsonAuthRequiredResponse(): Response {
|
|
@@ -17,7 +16,6 @@ export function htmlAuthRedirectResponse(
|
|
|
17
16
|
request: Request,
|
|
18
17
|
options: {
|
|
19
18
|
readonly absoluteReturnTo?: boolean
|
|
20
|
-
readonly audience?: AuthSessionAudience
|
|
21
19
|
} = {}
|
|
22
20
|
): Response {
|
|
23
21
|
const requestUrl = new URL(request.url)
|
|
@@ -25,9 +23,6 @@ export function htmlAuthRedirectResponse(
|
|
|
25
23
|
? new URL(returnToForRequest(request), requestUrl.origin).toString()
|
|
26
24
|
: returnToForRequest(request)
|
|
27
25
|
const params = new URLSearchParams({ returnTo: rawReturnTo })
|
|
28
|
-
if (options.absoluteReturnTo && options.audience) {
|
|
29
|
-
params.set("audience", options.audience)
|
|
30
|
-
}
|
|
31
26
|
|
|
32
27
|
return new Response(null, {
|
|
33
28
|
status: 302,
|
|
@@ -13,9 +13,7 @@ export function createSessionRenewalCookieHeaders(input: {
|
|
|
13
13
|
readonly session: AuthenticatedAuthSession
|
|
14
14
|
readonly csrfToken?: string
|
|
15
15
|
}): { readonly csrfToken: string; readonly headers: readonly [string, string] } | null {
|
|
16
|
-
const cookieOptions = input.host.auth.getCookieOptions(
|
|
17
|
-
audience: input.session.session.audience,
|
|
18
|
-
})
|
|
16
|
+
const cookieOptions = input.host.auth.getCookieOptions()
|
|
19
17
|
const sessionValue = getCookie(input.request, cookieOptions.sessionCookieName)
|
|
20
18
|
if (!sessionValue) {
|
|
21
19
|
return null
|
|
@@ -299,7 +299,7 @@ export function isSharedAccessPublicPath(pathname: string, requestMethod: string
|
|
|
299
299
|
/**
|
|
300
300
|
* The header selects the grant. File GET/HEAD routes also accept the selector in the query, because
|
|
301
301
|
* `<img>`, `<video>`, and download links cannot send headers. Either way it only names which
|
|
302
|
-
* grant cookie to read; the HttpOnly cookie remains the credential
|
|
302
|
+
* grant cookie to read; the HttpOnly cookie remains the credential.
|
|
303
303
|
*/
|
|
304
304
|
function selectSharedAccessGrant(request: Request): SharedAccessGrantSelection {
|
|
305
305
|
const header = request.headers.get(SHARED_ACCESS_GRANT_HEADER_NAME)
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { SixbApiBrowserPolicy
|
|
1
|
+
export type { SixbApiBrowserPolicy } from "./auth/browser-origin"
|
|
2
2
|
export type { SixbAuthExperienceOptions } from "./auth/experience"
|
|
3
3
|
export type { SixbSharedAccessOptions } from "./auth/shared-access"
|
|
4
4
|
export { createSixbServer, SixbServer, type SixbServerOptions } from "./server"
|
|
@@ -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 {}
|