@sixb/server 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/access-token-boundary.d.ts +3 -0
- package/dist/auth/access-token-boundary.d.ts.map +1 -1
- package/dist/auth/public-routes.d.ts.map +1 -1
- package/dist/auth/shared-access.d.ts +66 -0
- package/dist/auth/shared-access.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1454 -658
- package/dist/index.js.map +25 -20
- package/dist/openapi/security.d.ts +15 -1
- package/dist/openapi/security.d.ts.map +1 -1
- package/dist/openapi/tags.d.ts +6 -2
- package/dist/openapi/tags.d.ts.map +1 -1
- package/dist/registerRoutes.d.ts +2 -0
- package/dist/registerRoutes.d.ts.map +1 -1
- package/dist/routes/actions.d.ts.map +1 -1
- package/dist/routes/agents.d.ts +5 -5
- package/dist/routes/auth.d.ts +9 -9
- package/dist/routes/connector-connection-runs.d.ts +8 -8
- package/dist/routes/connector-connections.d.ts +4 -4
- package/dist/routes/datasets.d.ts +5 -3
- package/dist/routes/datasets.d.ts.map +1 -1
- package/dist/routes/files.d.ts.map +1 -1
- package/dist/routes/logs.d.ts +3 -3
- package/dist/routes/pipelines.d.ts +4 -0
- package/dist/routes/pipelines.d.ts.map +1 -1
- package/dist/routes/share-grants.d.ts +264 -0
- package/dist/routes/share-grants.d.ts.map +1 -0
- package/dist/routes/shared-access.d.ts +155 -0
- package/dist/routes/shared-access.d.ts.map +1 -0
- package/dist/routes/syncs.d.ts +2 -0
- package/dist/routes/syncs.d.ts.map +1 -1
- package/dist/routes/workflows.d.ts +7 -7
- package/dist/routes/ws/agents.d.ts.map +1 -1
- package/dist/routes/ws/logs.d.ts +10 -10
- package/dist/schemas/agents.d.ts +22 -30
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/ai-accounting.d.ts +332 -24
- package/dist/schemas/ai-accounting.d.ts.map +1 -1
- package/dist/schemas/auth.d.ts +40 -40
- package/dist/schemas/common.d.ts +6 -0
- package/dist/schemas/common.d.ts.map +1 -1
- package/dist/schemas/datasets.d.ts +28 -22
- package/dist/schemas/datasets.d.ts.map +1 -1
- package/dist/schemas/logs.d.ts +24 -24
- package/dist/schemas/pipelines.d.ts +36 -0
- package/dist/schemas/pipelines.d.ts.map +1 -1
- package/dist/schemas/share-grants.d.ts +518 -0
- package/dist/schemas/share-grants.d.ts.map +1 -0
- package/dist/schemas/shared-access.d.ts +42 -0
- package/dist/schemas/shared-access.d.ts.map +1 -0
- package/dist/schemas/syncs.d.ts +7 -0
- package/dist/schemas/syncs.d.ts.map +1 -1
- package/dist/schemas/workflows.d.ts +20 -20
- package/dist/server.d.ts +5 -0
- package/dist/server.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/auth/access-token-boundary.ts +17 -2
- package/src/auth/public-routes.ts +5 -0
- package/src/auth/shared-access.ts +376 -0
- package/src/index.ts +1 -0
- package/src/openapi/security.ts +20 -1
- package/src/openapi/tags.ts +4 -0
- package/src/registerRoutes.ts +6 -0
- package/src/routes/actions.ts +5 -10
- package/src/routes/agent-api-gateway.ts +1 -1
- package/src/routes/agents.ts +1 -1
- package/src/routes/files.ts +2 -6
- package/src/routes/share-grants.ts +238 -0
- package/src/routes/shared-access.ts +165 -0
- package/src/routes/ws/agents.ts +5 -3
- package/src/routes/ws/events.ts +1 -1
- package/src/schemas/agents.ts +1 -4
- package/src/schemas/ai-accounting.ts +3 -0
- package/src/schemas/common.ts +2 -0
- package/src/schemas/datasets.ts +2 -1
- package/src/schemas/share-grants.ts +109 -0
- package/src/schemas/shared-access.ts +31 -0
- package/src/server.ts +91 -1
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthorizationError,
|
|
3
|
+
type SharedAccessGrant,
|
|
4
|
+
ShareError,
|
|
5
|
+
type SixbHostView,
|
|
6
|
+
} from "@sixb/core"
|
|
7
|
+
import { ObjectNotFoundError } from "@sixb/core/storage"
|
|
8
|
+
import type { Elysia } from "elysia"
|
|
9
|
+
import { bearerSecurityRequirement } from "../auth/access-token-boundary"
|
|
10
|
+
import { requireRequestSixb } from "../auth/scope"
|
|
11
|
+
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
12
|
+
import { ErrorResponseSchema } from "../schemas/common"
|
|
13
|
+
import {
|
|
14
|
+
IssueSharedAccessGrantBodySchema,
|
|
15
|
+
IssueSharedAccessGrantResponseSchema,
|
|
16
|
+
ListSharedAccessGrantsQuerySchema,
|
|
17
|
+
ListSharedAccessGrantsResponseSchema,
|
|
18
|
+
RevokeSharedAccessGrantResponseSchema,
|
|
19
|
+
SharedAccessGrantIdParamsSchema,
|
|
20
|
+
SharedAccessGrantSchema,
|
|
21
|
+
} from "../schemas/share-grants"
|
|
22
|
+
|
|
23
|
+
const INTERNAL_ERROR = "[SixbServer] Shared-access operation failed."
|
|
24
|
+
const STORAGE_UNAVAILABLE_ERROR =
|
|
25
|
+
"[SixbServer] Shared-access grant storage is not configured on this runtime."
|
|
26
|
+
|
|
27
|
+
export function registerShareGrantRoutes(app: Elysia, _host: SixbHostView) {
|
|
28
|
+
return app
|
|
29
|
+
.post(
|
|
30
|
+
"/api/share-grants",
|
|
31
|
+
async (context) => {
|
|
32
|
+
const { body, set } = context
|
|
33
|
+
setNoStore(set)
|
|
34
|
+
try {
|
|
35
|
+
const invitation = await requireRequestSixb(context).shares.issueById({
|
|
36
|
+
definitionId: body.definitionId,
|
|
37
|
+
target: body.target,
|
|
38
|
+
destinationPath: body.destinationPath,
|
|
39
|
+
expiresAt: new Date(body.expiresAt),
|
|
40
|
+
})
|
|
41
|
+
const grant = serializeSharedAccessGrant(invitation.grant)
|
|
42
|
+
|
|
43
|
+
set.status = 201
|
|
44
|
+
return IssueSharedAccessGrantResponseSchema.parse({
|
|
45
|
+
grant,
|
|
46
|
+
url: sharedAccessUrl(grant.id, grant.destinationPath, invitation.secret),
|
|
47
|
+
})
|
|
48
|
+
} catch (error) {
|
|
49
|
+
return handleShareGrantRouteError(error, set)
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
body: IssueSharedAccessGrantBodySchema,
|
|
54
|
+
response: {
|
|
55
|
+
201: IssueSharedAccessGrantResponseSchema,
|
|
56
|
+
400: ErrorResponseSchema,
|
|
57
|
+
401: ErrorResponseSchema,
|
|
58
|
+
403: ErrorResponseSchema,
|
|
59
|
+
404: ErrorResponseSchema,
|
|
60
|
+
500: ErrorResponseSchema,
|
|
61
|
+
501: ErrorResponseSchema,
|
|
62
|
+
},
|
|
63
|
+
error: sharedAccessValidationError("Invalid shared-access grant request."),
|
|
64
|
+
detail: {
|
|
65
|
+
summary: "Issue a shared-access grant",
|
|
66
|
+
tags: [OPENAPI_TAGS.sharedAccess.name],
|
|
67
|
+
operationId: "issueSharedAccessGrant",
|
|
68
|
+
security: bearerSecurityRequirement("issueSharedAccessGrant"),
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
.get(
|
|
73
|
+
"/api/share-grants",
|
|
74
|
+
async (context) => {
|
|
75
|
+
const { query, set } = context
|
|
76
|
+
setNoStore(set)
|
|
77
|
+
try {
|
|
78
|
+
const result = await requireRequestSixb(context).shares.listById({
|
|
79
|
+
definitionId: query.definitionId,
|
|
80
|
+
primaryId: query.primaryId,
|
|
81
|
+
includeRevoked: query.includeRevoked,
|
|
82
|
+
includeExpired: query.includeExpired,
|
|
83
|
+
limit: query.limit,
|
|
84
|
+
offset: query.offset,
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
return ListSharedAccessGrantsResponseSchema.parse({
|
|
88
|
+
grants: result.grants.map(serializeSharedAccessGrant),
|
|
89
|
+
total: result.total,
|
|
90
|
+
hasMore: result.hasMore,
|
|
91
|
+
})
|
|
92
|
+
} catch (error) {
|
|
93
|
+
return handleShareGrantRouteError(error, set)
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
query: ListSharedAccessGrantsQuerySchema,
|
|
98
|
+
response: {
|
|
99
|
+
200: ListSharedAccessGrantsResponseSchema,
|
|
100
|
+
400: ErrorResponseSchema,
|
|
101
|
+
401: ErrorResponseSchema,
|
|
102
|
+
403: ErrorResponseSchema,
|
|
103
|
+
404: ErrorResponseSchema,
|
|
104
|
+
500: ErrorResponseSchema,
|
|
105
|
+
501: ErrorResponseSchema,
|
|
106
|
+
},
|
|
107
|
+
error: sharedAccessValidationError("Invalid shared-access grant query."),
|
|
108
|
+
detail: {
|
|
109
|
+
summary: "List shared-access grants",
|
|
110
|
+
tags: [OPENAPI_TAGS.sharedAccess.name],
|
|
111
|
+
operationId: "listSharedAccessGrants",
|
|
112
|
+
security: bearerSecurityRequirement("listSharedAccessGrants"),
|
|
113
|
+
},
|
|
114
|
+
}
|
|
115
|
+
)
|
|
116
|
+
.delete(
|
|
117
|
+
"/api/share-grants/:grantId",
|
|
118
|
+
async (context) => {
|
|
119
|
+
const { params, set } = context
|
|
120
|
+
setNoStore(set)
|
|
121
|
+
try {
|
|
122
|
+
const grant = await requireRequestSixb(context).shares.revoke(params.grantId)
|
|
123
|
+
if (!grant) {
|
|
124
|
+
set.status = 404
|
|
125
|
+
return { error: "[SixbServer] Shared-access grant not found." }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return RevokeSharedAccessGrantResponseSchema.parse({
|
|
129
|
+
grant: serializeSharedAccessGrant(grant),
|
|
130
|
+
})
|
|
131
|
+
} catch (error) {
|
|
132
|
+
return handleShareGrantRouteError(error, set)
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
params: SharedAccessGrantIdParamsSchema,
|
|
137
|
+
response: {
|
|
138
|
+
200: RevokeSharedAccessGrantResponseSchema,
|
|
139
|
+
400: ErrorResponseSchema,
|
|
140
|
+
401: ErrorResponseSchema,
|
|
141
|
+
403: ErrorResponseSchema,
|
|
142
|
+
404: ErrorResponseSchema,
|
|
143
|
+
500: ErrorResponseSchema,
|
|
144
|
+
501: ErrorResponseSchema,
|
|
145
|
+
},
|
|
146
|
+
error: sharedAccessValidationError("Invalid shared-access grant id."),
|
|
147
|
+
detail: {
|
|
148
|
+
summary: "Revoke a shared-access grant",
|
|
149
|
+
tags: [OPENAPI_TAGS.sharedAccess.name],
|
|
150
|
+
operationId: "revokeSharedAccessGrant",
|
|
151
|
+
security: bearerSecurityRequirement("revokeSharedAccessGrant"),
|
|
152
|
+
},
|
|
153
|
+
}
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function serializeSharedAccessGrant(grant: SharedAccessGrant) {
|
|
158
|
+
return SharedAccessGrantSchema.parse({
|
|
159
|
+
id: grant.id,
|
|
160
|
+
definitionId: grant.definitionId,
|
|
161
|
+
target: grant.target,
|
|
162
|
+
issuedBy: grant.issuedBy,
|
|
163
|
+
destinationPath: grant.destinationPath,
|
|
164
|
+
createdAt: grant.createdAt.toISOString(),
|
|
165
|
+
expiresAt: grant.expiresAt.toISOString(),
|
|
166
|
+
...(grant.revokedAt === undefined ? {} : { revokedAt: grant.revokedAt.toISOString() }),
|
|
167
|
+
...(grant.revokedBy === undefined ? {} : { revokedBy: grant.revokedBy }),
|
|
168
|
+
})
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function sharedAccessUrl(grantId: string, destinationPath: string, secret: string): string {
|
|
172
|
+
return `/shared/${encodeURIComponent(grantId)}${destinationPath}#${encodeURIComponent(secret)}`
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function handleShareGrantRouteError(
|
|
176
|
+
error: unknown,
|
|
177
|
+
set: { status?: number | string }
|
|
178
|
+
): { error: string } {
|
|
179
|
+
if (error instanceof ShareError) {
|
|
180
|
+
set.status = shareErrorStatus(error)
|
|
181
|
+
if (error.reason === "storage_failure") return { error: INTERNAL_ERROR }
|
|
182
|
+
if (error.reason === "storage_unavailable") return { error: STORAGE_UNAVAILABLE_ERROR }
|
|
183
|
+
if (error.reason === "unauthenticated") return { error: "Authentication required." }
|
|
184
|
+
return { error: error.message }
|
|
185
|
+
}
|
|
186
|
+
if (error instanceof AuthorizationError) {
|
|
187
|
+
set.status = 403
|
|
188
|
+
return { error: error.message }
|
|
189
|
+
}
|
|
190
|
+
if (error instanceof ObjectNotFoundError) {
|
|
191
|
+
set.status = 404
|
|
192
|
+
return { error: error.message }
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
set.status = 500
|
|
196
|
+
return { error: INTERNAL_ERROR }
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function shareErrorStatus(error: ShareError): number {
|
|
200
|
+
switch (error.reason) {
|
|
201
|
+
case "invalid_input":
|
|
202
|
+
return 400
|
|
203
|
+
case "not_found":
|
|
204
|
+
return 404
|
|
205
|
+
case "unauthenticated":
|
|
206
|
+
return 401
|
|
207
|
+
case "storage_unavailable":
|
|
208
|
+
return 501
|
|
209
|
+
case "storage_failure":
|
|
210
|
+
return 500
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function sharedAccessValidationError(message: string) {
|
|
215
|
+
return ({
|
|
216
|
+
code,
|
|
217
|
+
set,
|
|
218
|
+
}: {
|
|
219
|
+
code: unknown
|
|
220
|
+
set: { status?: number | string; headers?: unknown }
|
|
221
|
+
}) => {
|
|
222
|
+
if (code !== "VALIDATION") return
|
|
223
|
+
setNoStore(set)
|
|
224
|
+
set.status = 400
|
|
225
|
+
return { error: message }
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function setNoStore(set: { headers?: unknown }): void {
|
|
230
|
+
if (set.headers instanceof Headers) {
|
|
231
|
+
set.headers.set("cache-control", "no-store")
|
|
232
|
+
return
|
|
233
|
+
}
|
|
234
|
+
if (!set.headers || typeof set.headers !== "object" || Array.isArray(set.headers)) {
|
|
235
|
+
set.headers = {}
|
|
236
|
+
}
|
|
237
|
+
;(set.headers as Record<string, string>)["cache-control"] = "no-store"
|
|
238
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { SharedSessionContext } from "@sixb/core/internal/shares"
|
|
2
|
+
import type { Elysia } from "elysia"
|
|
3
|
+
import { CSRF_TOKEN_RESPONSE_HEADER_NAME } from "../auth/csrf"
|
|
4
|
+
import {
|
|
5
|
+
type SharedAccessBoundary,
|
|
6
|
+
sharedAccessForbiddenResponse,
|
|
7
|
+
sharedAccessSecurityHeaders,
|
|
8
|
+
sharedAccessUnauthenticatedResponse,
|
|
9
|
+
sharedAccessUnavailableResponse,
|
|
10
|
+
} from "../auth/shared-access"
|
|
11
|
+
import { SIXB_CSRF_SECURITY_REQUIREMENT } from "../openapi/security"
|
|
12
|
+
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
13
|
+
import { ErrorResponseSchema } from "../schemas/common"
|
|
14
|
+
import {
|
|
15
|
+
ExchangeSharedAccessBodySchema,
|
|
16
|
+
SharedAccessGrantParamsSchema,
|
|
17
|
+
SharedAccessSessionResponseSchema,
|
|
18
|
+
SharedAccessSignOutResponseSchema,
|
|
19
|
+
} from "../schemas/shared-access"
|
|
20
|
+
|
|
21
|
+
export function registerSharedAccessRoutes(app: Elysia, boundary: SharedAccessBoundary) {
|
|
22
|
+
return app
|
|
23
|
+
.post(
|
|
24
|
+
"/api/shared-access/:grantId/exchange",
|
|
25
|
+
async ({ body, params, request }) => {
|
|
26
|
+
try {
|
|
27
|
+
const resolved = await boundary.exchange(request, params.grantId, body.secret)
|
|
28
|
+
if (!resolved) return sharedAccessUnauthenticatedResponse()
|
|
29
|
+
return sharedSessionResponse(resolved.context, resolved.cookies)
|
|
30
|
+
} catch {
|
|
31
|
+
return sharedAccessUnavailableResponse()
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
params: SharedAccessGrantParamsSchema,
|
|
36
|
+
body: ExchangeSharedAccessBodySchema,
|
|
37
|
+
response: {
|
|
38
|
+
200: SharedAccessSessionResponseSchema,
|
|
39
|
+
401: ErrorResponseSchema,
|
|
40
|
+
503: ErrorResponseSchema,
|
|
41
|
+
},
|
|
42
|
+
error: sharedAccessRouteError,
|
|
43
|
+
detail: {
|
|
44
|
+
summary: "Exchange a shared link for a short-lived session",
|
|
45
|
+
tags: [OPENAPI_TAGS.sharedAccess.name],
|
|
46
|
+
operationId: "exchangeSharedAccess",
|
|
47
|
+
security: [],
|
|
48
|
+
},
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
.get(
|
|
52
|
+
"/api/shared-access/:grantId/session",
|
|
53
|
+
async ({ params, request }) => {
|
|
54
|
+
try {
|
|
55
|
+
const resolved = await boundary.resolveSession(request, params.grantId)
|
|
56
|
+
if (!resolved) {
|
|
57
|
+
return withSetCookies(
|
|
58
|
+
sharedAccessUnauthenticatedResponse(),
|
|
59
|
+
boundary.clearCookieHeaders(request, params.grantId)
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
return sharedSessionResponse(resolved.context, resolved.cookies)
|
|
63
|
+
} catch {
|
|
64
|
+
return sharedAccessUnavailableResponse()
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
params: SharedAccessGrantParamsSchema,
|
|
69
|
+
response: {
|
|
70
|
+
200: SharedAccessSessionResponseSchema,
|
|
71
|
+
401: ErrorResponseSchema,
|
|
72
|
+
503: ErrorResponseSchema,
|
|
73
|
+
},
|
|
74
|
+
error: sharedAccessRouteError,
|
|
75
|
+
detail: {
|
|
76
|
+
summary: "Get the current shared-access session",
|
|
77
|
+
tags: [OPENAPI_TAGS.sharedAccess.name],
|
|
78
|
+
operationId: "getSharedAccessSession",
|
|
79
|
+
security: [],
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
.post(
|
|
84
|
+
"/api/shared-access/:grantId/sign-out",
|
|
85
|
+
async ({ params, request }) => {
|
|
86
|
+
try {
|
|
87
|
+
const result = await boundary.signOut(request, params.grantId)
|
|
88
|
+
if (result.kind === "csrf") return sharedAccessForbiddenResponse()
|
|
89
|
+
if (result.kind === "invalid") {
|
|
90
|
+
return withSetCookies(sharedAccessUnauthenticatedResponse(), result.setCookies)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const response = new Response(JSON.stringify({ signedOut: true }), {
|
|
94
|
+
status: 200,
|
|
95
|
+
headers: sharedAccessSecurityHeaders(),
|
|
96
|
+
})
|
|
97
|
+
return withSetCookies(response, result.setCookies)
|
|
98
|
+
} catch {
|
|
99
|
+
return sharedAccessUnavailableResponse()
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
params: SharedAccessGrantParamsSchema,
|
|
104
|
+
response: {
|
|
105
|
+
200: SharedAccessSignOutResponseSchema,
|
|
106
|
+
401: ErrorResponseSchema,
|
|
107
|
+
403: ErrorResponseSchema,
|
|
108
|
+
503: ErrorResponseSchema,
|
|
109
|
+
},
|
|
110
|
+
error: sharedAccessRouteError,
|
|
111
|
+
detail: {
|
|
112
|
+
summary: "Sign out a shared-access session",
|
|
113
|
+
tags: [OPENAPI_TAGS.sharedAccess.name],
|
|
114
|
+
operationId: "signOutSharedAccess",
|
|
115
|
+
security: SIXB_CSRF_SECURITY_REQUIREMENT,
|
|
116
|
+
},
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function sharedSessionResponse(
|
|
122
|
+
context: SharedSessionContext,
|
|
123
|
+
cookies: { readonly setCookies: readonly string[]; readonly csrfToken: string }
|
|
124
|
+
): Response {
|
|
125
|
+
const headers = sharedAccessSecurityHeaders()
|
|
126
|
+
headers.set(CSRF_TOKEN_RESPONSE_HEADER_NAME, cookies.csrfToken)
|
|
127
|
+
for (const cookie of cookies.setCookies) headers.append("set-cookie", cookie)
|
|
128
|
+
return new Response(
|
|
129
|
+
JSON.stringify({
|
|
130
|
+
grantId: context.grantId,
|
|
131
|
+
destinationPath: context.destinationPath,
|
|
132
|
+
expiresAt: context.expiresAt.toISOString(),
|
|
133
|
+
absoluteExpiresAt: context.absoluteExpiresAt.toISOString(),
|
|
134
|
+
csrfToken: cookies.csrfToken,
|
|
135
|
+
}),
|
|
136
|
+
{ status: 200, headers }
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function withSetCookies(response: Response, setCookies: readonly string[]): Response {
|
|
141
|
+
for (const cookie of setCookies) response.headers.append("set-cookie", cookie)
|
|
142
|
+
return response
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function sharedAccessRouteError(context: {
|
|
146
|
+
readonly code: unknown
|
|
147
|
+
readonly error: unknown
|
|
148
|
+
}): Response {
|
|
149
|
+
if (context.code === "PARSE" || isRequestValidationError(context)) {
|
|
150
|
+
return sharedAccessUnauthenticatedResponse()
|
|
151
|
+
}
|
|
152
|
+
return sharedAccessUnavailableResponse()
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function isRequestValidationError(context: {
|
|
156
|
+
readonly code: unknown
|
|
157
|
+
readonly error: unknown
|
|
158
|
+
}): boolean {
|
|
159
|
+
if (context.code !== "VALIDATION" || !isRecord(context.error)) return false
|
|
160
|
+
return ["body", "params", "query", "headers", "cookie"].includes(String(context.error.type))
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
164
|
+
return typeof value === "object" && value !== null
|
|
165
|
+
}
|
package/src/routes/ws/agents.ts
CHANGED
|
@@ -2,12 +2,14 @@ import type { OntologySource } from "@sixb/core"
|
|
|
2
2
|
import {
|
|
3
3
|
AGENT_ACTIVITY_STREAM_ID,
|
|
4
4
|
type AgentRunActivityEvent,
|
|
5
|
-
agentActivityStreamDefinition,
|
|
6
|
-
agentRunStreamDefinition,
|
|
7
|
-
agentRunStreamId,
|
|
8
5
|
isAgentRunActivityEvent,
|
|
9
6
|
} from "@sixb/core/agents/streams"
|
|
10
7
|
import { BrokerCursorExpiredError, type BrokerRecord } from "@sixb/core/broker"
|
|
8
|
+
import {
|
|
9
|
+
agentActivityStreamDefinition,
|
|
10
|
+
agentRunStreamDefinition,
|
|
11
|
+
agentRunStreamId,
|
|
12
|
+
} from "@sixb/core/internal/agents/streams"
|
|
11
13
|
import type { Sixb } from "@sixb/core/internal/request-execution"
|
|
12
14
|
import type { Elysia } from "elysia"
|
|
13
15
|
import { z } from "zod"
|
package/src/routes/ws/events.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DomainEvent } from "@sixb/core"
|
|
2
|
-
import { scopeKeysForEvent } from "@sixb/core/
|
|
2
|
+
import { scopeKeysForEvent } from "@sixb/core/internal/event-scope"
|
|
3
3
|
import type { Elysia } from "elysia"
|
|
4
4
|
import { z } from "zod"
|
|
5
5
|
import { EVENT_TOPICS, EVENT_TYPES } from "../../schemas/events"
|
package/src/schemas/agents.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { AiCostSummarySchema } from "./ai-accounting"
|
|
|
11
11
|
import { AiUsageSummarySchema } from "./ai-usage"
|
|
12
12
|
import { JsonValueSchema, sixbFailureSchema } from "./common"
|
|
13
13
|
import { FileRefSchema } from "./files"
|
|
14
|
-
import { LanguageModelRefSchema,
|
|
14
|
+
import { LanguageModelRefSchema, ModelReasoningSchema } from "./models"
|
|
15
15
|
|
|
16
16
|
export const AgentRunFailureSchema: z.ZodType<SixbFailure<AgentRunFailureCode>> =
|
|
17
17
|
sixbFailureSchema(AGENT_RUN_FAILURE_CODES)
|
|
@@ -70,9 +70,6 @@ export const AgentContextPartSchema = AgentContextEntryInputSchema.extend({
|
|
|
70
70
|
type: z.literal("context"),
|
|
71
71
|
})
|
|
72
72
|
|
|
73
|
-
export const AgentReasoningLevelSchema = ModelReasoningLevelSchema
|
|
74
|
-
export const AgentReasoningSchema = ModelReasoningSchema
|
|
75
|
-
|
|
76
73
|
export const AgentDescriptorSchema = z.object({
|
|
77
74
|
name: z.string(),
|
|
78
75
|
model: LanguageModelRefSchema,
|
|
@@ -193,6 +193,9 @@ export const AiModelCallAccountingItemSchema = z.object({
|
|
|
193
193
|
usage: AiModelCallUsageRecordSchema,
|
|
194
194
|
attribution: z
|
|
195
195
|
.discriminatedUnion("kind", [
|
|
196
|
+
z.object({ kind: z.literal("request"), requestId: z.string() }),
|
|
197
|
+
z.object({ kind: z.literal("action"), actionId: z.string(), actionRunId: z.string() }),
|
|
198
|
+
z.object({ kind: z.literal("workflow"), workflowId: z.string(), workflowRunId: z.string() }),
|
|
196
199
|
z.object({
|
|
197
200
|
kind: z.literal("agent"),
|
|
198
201
|
agentRunId: z.string(),
|
package/src/schemas/common.ts
CHANGED
|
@@ -47,6 +47,8 @@ export function sixbFailureSchema<
|
|
|
47
47
|
retryable: z.boolean(),
|
|
48
48
|
at: z.string().datetime(),
|
|
49
49
|
details: JsonValueSchema.optional(),
|
|
50
|
+
httpStatus: z.number().int().min(100).max(599).optional(),
|
|
51
|
+
redacted: z.literal(true).optional(),
|
|
50
52
|
truncated: z.literal(true).optional(),
|
|
51
53
|
})
|
|
52
54
|
}
|
package/src/schemas/datasets.ts
CHANGED
|
@@ -43,6 +43,7 @@ export const DatasetDefinitionSchema = z.object({
|
|
|
43
43
|
id: z.string(),
|
|
44
44
|
description: z.string().optional(),
|
|
45
45
|
primaryKey: z.union([z.string(), z.array(z.string()).min(2)]).optional(),
|
|
46
|
+
sequenceBy: z.string().optional(),
|
|
46
47
|
partitionBy: z.array(z.string()).optional(),
|
|
47
48
|
schema: DatasetSchema,
|
|
48
49
|
})
|
|
@@ -53,7 +54,7 @@ export const DatasetVersionRefSchema = z.object({
|
|
|
53
54
|
})
|
|
54
55
|
|
|
55
56
|
export const DatasetProducerSchema = z.object({
|
|
56
|
-
kind: z.enum(["sync", "pipeline"]),
|
|
57
|
+
kind: z.enum(["sync", "pipeline", "ingest"]),
|
|
57
58
|
id: z.string().optional(),
|
|
58
59
|
runId: z.string().optional(),
|
|
59
60
|
})
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { z } from "zod"
|
|
2
|
+
|
|
3
|
+
const StoredIdentifierSchema = z.string().min(1).refine(isStoredIdentifier, {
|
|
4
|
+
message: "stored identifier must not be blank or contain NUL bytes",
|
|
5
|
+
})
|
|
6
|
+
const Rfc3339DateSchema = z.string().datetime({ offset: true })
|
|
7
|
+
const DestinationPathSchema = z.string().min(1).max(4_096)
|
|
8
|
+
|
|
9
|
+
const QueryBooleanSchema = z.preprocess((value) => {
|
|
10
|
+
if (value === "true" || value === true) return true
|
|
11
|
+
if (value === "false" || value === false) return false
|
|
12
|
+
return value
|
|
13
|
+
}, z.boolean())
|
|
14
|
+
|
|
15
|
+
const ShareGrantListLimitSchema = z.preprocess(
|
|
16
|
+
parseUnsignedQueryInteger,
|
|
17
|
+
z.number().int().min(1).max(200)
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
const ShareGrantListOffsetSchema = z.preprocess(
|
|
21
|
+
parseUnsignedQueryInteger,
|
|
22
|
+
z.number().int().min(0).max(Number.MAX_SAFE_INTEGER)
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
function parseUnsignedQueryInteger(value: unknown): unknown {
|
|
26
|
+
if (typeof value !== "string" || !/^\d+$/.test(value)) return value
|
|
27
|
+
const parsed = Number(value)
|
|
28
|
+
return Number.isSafeInteger(parsed) ? parsed : value
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const ShareGrantTargetSchema = z.object({
|
|
32
|
+
objectTypeId: StoredIdentifierSchema,
|
|
33
|
+
primaryId: StoredIdentifierSchema,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const ShareGrantTargetInputSchema = z.object({
|
|
37
|
+
objectTypeId: StoredIdentifierSchema,
|
|
38
|
+
primaryId: z.string().min(1).refine(isStoredIdentifier, {
|
|
39
|
+
message: "primaryId must not be blank or contain NUL bytes",
|
|
40
|
+
}),
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const AuthorizablePrincipalSchema = z.object({
|
|
44
|
+
type: z.enum(["user", "serviceAccount"]),
|
|
45
|
+
id: StoredIdentifierSchema,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const PrincipalSchema = z.object({
|
|
49
|
+
type: z.enum(["user", "serviceAccount", "system"]),
|
|
50
|
+
id: StoredIdentifierSchema,
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
export const SharedAccessGrantSchema = z.object({
|
|
54
|
+
id: StoredIdentifierSchema,
|
|
55
|
+
definitionId: StoredIdentifierSchema,
|
|
56
|
+
target: ShareGrantTargetSchema,
|
|
57
|
+
issuedBy: AuthorizablePrincipalSchema,
|
|
58
|
+
destinationPath: DestinationPathSchema,
|
|
59
|
+
createdAt: Rfc3339DateSchema,
|
|
60
|
+
expiresAt: Rfc3339DateSchema,
|
|
61
|
+
revokedAt: Rfc3339DateSchema.optional(),
|
|
62
|
+
revokedBy: PrincipalSchema.optional(),
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
export const IssueSharedAccessGrantBodySchema = z.object({
|
|
66
|
+
definitionId: StoredIdentifierSchema,
|
|
67
|
+
target: ShareGrantTargetInputSchema,
|
|
68
|
+
destinationPath: DestinationPathSchema,
|
|
69
|
+
expiresAt: Rfc3339DateSchema,
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
export const IssueSharedAccessGrantResponseSchema = z.object({
|
|
73
|
+
grant: SharedAccessGrantSchema,
|
|
74
|
+
/** Same-origin URL. The bearer secret exists only in its fragment. */
|
|
75
|
+
url: z.string().startsWith("/shared/"),
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
export const ListSharedAccessGrantsQuerySchema = z.object({
|
|
79
|
+
definitionId: StoredIdentifierSchema,
|
|
80
|
+
primaryId: z
|
|
81
|
+
.string()
|
|
82
|
+
.min(1)
|
|
83
|
+
.refine(isStoredIdentifier, {
|
|
84
|
+
message: "primaryId must not be blank or contain NUL bytes",
|
|
85
|
+
})
|
|
86
|
+
.optional(),
|
|
87
|
+
includeRevoked: QueryBooleanSchema.optional(),
|
|
88
|
+
includeExpired: QueryBooleanSchema.optional(),
|
|
89
|
+
limit: ShareGrantListLimitSchema.optional(),
|
|
90
|
+
offset: ShareGrantListOffsetSchema.optional(),
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
export const ListSharedAccessGrantsResponseSchema = z.object({
|
|
94
|
+
grants: z.array(SharedAccessGrantSchema),
|
|
95
|
+
hasMore: z.boolean(),
|
|
96
|
+
total: z.number().int().nonnegative(),
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
export const SharedAccessGrantIdParamsSchema = z.object({
|
|
100
|
+
grantId: StoredIdentifierSchema,
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
export const RevokeSharedAccessGrantResponseSchema = z.object({
|
|
104
|
+
grant: SharedAccessGrantSchema,
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
function isStoredIdentifier(value: string): boolean {
|
|
108
|
+
return value.trim().length > 0 && !value.includes("\0")
|
|
109
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from "zod"
|
|
2
|
+
|
|
3
|
+
const StoredIdentifierSchema = z
|
|
4
|
+
.string()
|
|
5
|
+
.min(1)
|
|
6
|
+
.max(128)
|
|
7
|
+
.refine((value) => value.trim() === value && !value.includes("\0"), {
|
|
8
|
+
message: "stored identifier must not be blank or contain NUL bytes",
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
const Rfc3339DateSchema = z.string().datetime({ offset: true })
|
|
12
|
+
|
|
13
|
+
export const SharedAccessGrantParamsSchema = z.object({
|
|
14
|
+
grantId: StoredIdentifierSchema,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export const ExchangeSharedAccessBodySchema = z.object({
|
|
18
|
+
secret: z.string().regex(/^[A-Za-z0-9_-]{43}$/),
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
export const SharedAccessSessionResponseSchema = z.object({
|
|
22
|
+
grantId: StoredIdentifierSchema,
|
|
23
|
+
destinationPath: z.string().min(1).max(4_096),
|
|
24
|
+
expiresAt: Rfc3339DateSchema,
|
|
25
|
+
absoluteExpiresAt: Rfc3339DateSchema,
|
|
26
|
+
csrfToken: z.string().regex(/^[A-Za-z0-9_-]{43}$/),
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
export const SharedAccessSignOutResponseSchema = z.object({
|
|
30
|
+
signedOut: z.literal(true),
|
|
31
|
+
})
|