@sixb/server 0.1.17 → 0.1.18
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/experience.d.ts +5 -1
- package/dist/auth/experience.d.ts.map +1 -1
- package/dist/files/content.d.ts +0 -1
- package/dist/files/content.d.ts.map +1 -1
- package/dist/index.js +204 -136
- package/dist/index.js.map +24 -24
- package/dist/routes/agents.d.ts +48 -28
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/auth.d.ts +3 -2
- package/dist/routes/auth.d.ts.map +1 -1
- package/dist/routes/datasets.d.ts +4 -1
- package/dist/routes/datasets.d.ts.map +1 -1
- package/dist/routes/files.d.ts.map +1 -1
- package/dist/routes/models.d.ts +1 -0
- package/dist/routes/models.d.ts.map +1 -1
- package/dist/routes/objects.d.ts +21 -4
- package/dist/routes/objects.d.ts.map +1 -1
- package/dist/routes/project.d.ts +2 -0
- package/dist/routes/project.d.ts.map +1 -1
- package/dist/routes/workflows.d.ts +3 -0
- package/dist/routes/workflows.d.ts.map +1 -1
- package/dist/routes/ws/events.d.ts.map +1 -1
- package/dist/routes/ws/subscription-hub.d.ts +5 -0
- package/dist/routes/ws/subscription-hub.d.ts.map +1 -1
- package/dist/schemas/agents.d.ts +222 -123
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/ai-accounting.d.ts +10 -10
- package/dist/schemas/auth.d.ts +7 -0
- package/dist/schemas/auth.d.ts.map +1 -1
- package/dist/schemas/common.d.ts +8 -0
- package/dist/schemas/common.d.ts.map +1 -1
- package/dist/schemas/datasets.d.ts +18 -3
- package/dist/schemas/datasets.d.ts.map +1 -1
- package/dist/schemas/event-payloads.d.ts +39 -0
- package/dist/schemas/event-payloads.d.ts.map +1 -1
- package/dist/schemas/files.d.ts +1 -1
- package/dist/schemas/files.d.ts.map +1 -1
- package/dist/schemas/models.d.ts +10 -0
- package/dist/schemas/models.d.ts.map +1 -1
- package/dist/schemas/objects.d.ts +32 -0
- package/dist/schemas/objects.d.ts.map +1 -1
- package/dist/schemas/project.d.ts +8 -0
- package/dist/schemas/project.d.ts.map +1 -1
- package/dist/schemas/workflows.d.ts +17 -0
- package/dist/schemas/workflows.d.ts.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/auth/experience.ts +20 -2
- package/src/files/content.ts +43 -88
- package/src/routes/agents.ts +29 -9
- package/src/routes/auth.ts +84 -19
- package/src/routes/datasets.ts +12 -43
- package/src/routes/files.ts +3 -1
- package/src/routes/models.ts +3 -0
- package/src/routes/objects.ts +12 -2
- package/src/routes/project.ts +2 -1
- package/src/routes/workflows.ts +5 -0
- package/src/routes/ws/events.ts +5 -3
- package/src/routes/ws/subscription-hub.ts +20 -5
- package/src/schemas/agents.ts +28 -3
- package/src/schemas/auth.ts +5 -0
- package/src/schemas/common.ts +3 -0
- package/src/schemas/datasets.ts +23 -1
- package/src/schemas/event-payloads.ts +3 -1
- package/src/schemas/files.ts +7 -1
- package/src/schemas/models.ts +2 -0
- package/src/schemas/objects.ts +13 -0
- package/src/schemas/project.ts +4 -0
- package/src/server.ts +2 -1
package/src/routes/auth.ts
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
isOidcAuthStrategy,
|
|
23
23
|
type MagicLinkAuthStrategy,
|
|
24
24
|
type MemberSummary,
|
|
25
|
+
type OidcStartSignInResult,
|
|
25
26
|
SignInRefusedError,
|
|
26
27
|
shouldUseSecureCookies,
|
|
27
28
|
verifyCsrfToken,
|
|
@@ -51,7 +52,7 @@ import { CSRF_TOKEN_RESPONSE_HEADER_NAME } from "../auth/csrf"
|
|
|
51
52
|
import {
|
|
52
53
|
customAuthExperienceAssetResponse,
|
|
53
54
|
customAuthExperienceResponse,
|
|
54
|
-
type
|
|
55
|
+
type ProjectAuthExperience,
|
|
55
56
|
} from "../auth/experience"
|
|
56
57
|
import { ClientAddressRateLimiter } from "../auth/rate-limit"
|
|
57
58
|
import { requestCaller } from "../auth/scope"
|
|
@@ -142,7 +143,7 @@ export interface AuthRoutesOptions {
|
|
|
142
143
|
request: Request,
|
|
143
144
|
input: AuthInvitationRedirectInput
|
|
144
145
|
) => AuthInvitationRedirectContext
|
|
145
|
-
readonly authExperience?:
|
|
146
|
+
readonly authExperience?: ProjectAuthExperience
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: AuthRoutesOptions) {
|
|
@@ -440,7 +441,7 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
|
|
|
440
441
|
})
|
|
441
442
|
// Access tokens are not sessions; a native client's session has no cookies to renew.
|
|
442
443
|
if (!caller.authenticated || caller.credentialSource !== "session") {
|
|
443
|
-
return
|
|
444
|
+
return signedOutSessionResponse(host)
|
|
444
445
|
}
|
|
445
446
|
// A native client belongs to no web app; tell it whether its user may open Atlas.
|
|
446
447
|
if (caller.session.bearer) {
|
|
@@ -453,7 +454,7 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
|
|
|
453
454
|
? await host.auth.getSession(request, { ...authOptions, sessionActivity: "foreground" })
|
|
454
455
|
: caller
|
|
455
456
|
if (!session.authenticated) {
|
|
456
|
-
return
|
|
457
|
+
return signedOutSessionResponse(host)
|
|
457
458
|
}
|
|
458
459
|
|
|
459
460
|
const cookieOptions = host.auth.getCookieOptions(authOptions)
|
|
@@ -742,7 +743,7 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
|
|
|
742
743
|
summary: "Create a personal access token",
|
|
743
744
|
tags: [OPENAPI_TAGS.authAccessTokens.name],
|
|
744
745
|
operationId: "createAuthPersonalAccessToken",
|
|
745
|
-
security:
|
|
746
|
+
security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT,
|
|
746
747
|
},
|
|
747
748
|
}
|
|
748
749
|
)
|
|
@@ -978,7 +979,7 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
|
|
|
978
979
|
summary: "Create an access token for an auth service account",
|
|
979
980
|
tags: [OPENAPI_TAGS.authServiceAccounts.name],
|
|
980
981
|
operationId: "createAuthServiceAccountAccessToken",
|
|
981
|
-
security:
|
|
982
|
+
security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT,
|
|
982
983
|
},
|
|
983
984
|
}
|
|
984
985
|
)
|
|
@@ -1383,9 +1384,10 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
|
|
|
1383
1384
|
const existingPending = getCookie(request, MAGIC_LINK_PENDING_COOKIE_NAME)?.trim()
|
|
1384
1385
|
response.headers.append(
|
|
1385
1386
|
"set-cookie",
|
|
1386
|
-
|
|
1387
|
+
callbackCookieHeader({
|
|
1387
1388
|
request,
|
|
1388
1389
|
host,
|
|
1390
|
+
name: MAGIC_LINK_PENDING_COOKIE_NAME,
|
|
1389
1391
|
value: result.status === "sent" ? pending.secret : existingPending || pending.secret,
|
|
1390
1392
|
maxAgeSeconds: magicLinkPendingCookieMaxAgeSeconds(strategy),
|
|
1391
1393
|
})
|
|
@@ -1401,7 +1403,7 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
|
|
|
1401
1403
|
returnTo: authRedirect.returnTo,
|
|
1402
1404
|
requestOrigin: authRedirect.requestOrigin,
|
|
1403
1405
|
})
|
|
1404
|
-
return
|
|
1406
|
+
return oidcSignInRedirect(request, host, result)
|
|
1405
1407
|
}
|
|
1406
1408
|
|
|
1407
1409
|
return strategyNotImplementedResponse("Sign-in is not implemented yet.")
|
|
@@ -1441,7 +1443,7 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
|
|
|
1441
1443
|
returnTo: authRedirect.returnTo,
|
|
1442
1444
|
requestOrigin: authRedirect.requestOrigin,
|
|
1443
1445
|
})
|
|
1444
|
-
return
|
|
1446
|
+
return oidcSignInRedirect(request, host, result)
|
|
1445
1447
|
}
|
|
1446
1448
|
|
|
1447
1449
|
return strategyNotImplementedResponse("Sign-in is not implemented yet.")
|
|
@@ -1528,8 +1530,15 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
|
|
|
1528
1530
|
const now = new Date()
|
|
1529
1531
|
const sessionCredential = createSessionCredential()
|
|
1530
1532
|
const device = resolveSessionDevice(request)
|
|
1533
|
+
const state = new URL(request.url).searchParams.get("state")
|
|
1531
1534
|
|
|
1535
|
+
let response: Response
|
|
1532
1536
|
try {
|
|
1537
|
+
if (!state || !matchesOidcStateCookie(request, state)) {
|
|
1538
|
+
throw new Error(
|
|
1539
|
+
"[SixbServer] OIDC callback reached a browser that did not start this sign-in."
|
|
1540
|
+
)
|
|
1541
|
+
}
|
|
1533
1542
|
const authOptions = resolveAuthOptions(options, request)
|
|
1534
1543
|
const result = await strategy.completeOidcSignIn({
|
|
1535
1544
|
projectId: host.id,
|
|
@@ -1546,7 +1555,7 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
|
|
|
1546
1555
|
},
|
|
1547
1556
|
})
|
|
1548
1557
|
|
|
1549
|
-
|
|
1558
|
+
response = sessionCallbackCompletionResponse({
|
|
1550
1559
|
host,
|
|
1551
1560
|
request,
|
|
1552
1561
|
apiOrigin: options.resolveAuthRequestOrigin(request),
|
|
@@ -1557,11 +1566,25 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
|
|
|
1557
1566
|
})
|
|
1558
1567
|
} catch (error) {
|
|
1559
1568
|
logAuthCallbackError("OIDC", error)
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1569
|
+
response =
|
|
1570
|
+
error instanceof SignInRefusedError
|
|
1571
|
+
? htmlMessageResponse(signInRefusalMessage(error), 403, "You can't sign in")
|
|
1572
|
+
: htmlMessageResponse("This sign-in attempt could not be completed.", 400)
|
|
1564
1573
|
}
|
|
1574
|
+
// Completed or refused, this attempt is over for this browser.
|
|
1575
|
+
if (state) {
|
|
1576
|
+
response.headers.append(
|
|
1577
|
+
"set-cookie",
|
|
1578
|
+
callbackCookieHeader({
|
|
1579
|
+
request,
|
|
1580
|
+
host,
|
|
1581
|
+
name: oidcStateCookieName(state),
|
|
1582
|
+
value: "",
|
|
1583
|
+
maxAgeSeconds: 0,
|
|
1584
|
+
})
|
|
1585
|
+
)
|
|
1586
|
+
}
|
|
1587
|
+
return response
|
|
1565
1588
|
}
|
|
1566
1589
|
|
|
1567
1590
|
return strategyNotImplementedResponse("Auth callback is not implemented yet.")
|
|
@@ -1670,16 +1693,17 @@ function matchesMagicLinkRequester(pendingSecret: string, requesterHash: string)
|
|
|
1670
1693
|
return expected.length === provided.length && timingSafeEqual(expected, provided)
|
|
1671
1694
|
}
|
|
1672
1695
|
|
|
1673
|
-
// SameSite=Lax, not Strict: the emailed link
|
|
1674
|
-
//
|
|
1675
|
-
function
|
|
1696
|
+
// SameSite=Lax, not Strict: the emailed link and the identity provider's redirect arrive as
|
|
1697
|
+
// cross-site top-level navigations, and the cookie must accompany that GET.
|
|
1698
|
+
function callbackCookieHeader(params: {
|
|
1676
1699
|
readonly request: Request
|
|
1677
1700
|
readonly host: SixbHostView
|
|
1701
|
+
readonly name: string
|
|
1678
1702
|
readonly value: string
|
|
1679
1703
|
readonly maxAgeSeconds: number
|
|
1680
1704
|
}): string {
|
|
1681
1705
|
const parts = [
|
|
1682
|
-
`${
|
|
1706
|
+
`${params.name}=${params.value}`,
|
|
1683
1707
|
"Path=/auth/callback",
|
|
1684
1708
|
"SameSite=Lax",
|
|
1685
1709
|
"HttpOnly",
|
|
@@ -1736,9 +1760,10 @@ async function completeMagicLinkCallback(input: {
|
|
|
1736
1760
|
if (input.clearPendingCookie) {
|
|
1737
1761
|
response.headers.append(
|
|
1738
1762
|
"set-cookie",
|
|
1739
|
-
|
|
1763
|
+
callbackCookieHeader({
|
|
1740
1764
|
request: input.request,
|
|
1741
1765
|
host: input.host,
|
|
1766
|
+
name: MAGIC_LINK_PENDING_COOKIE_NAME,
|
|
1742
1767
|
value: "",
|
|
1743
1768
|
maxAgeSeconds: 0,
|
|
1744
1769
|
})
|
|
@@ -1750,6 +1775,41 @@ async function completeMagicLinkCallback(input: {
|
|
|
1750
1775
|
}
|
|
1751
1776
|
}
|
|
1752
1777
|
|
|
1778
|
+
// Binds an OIDC sign-in to the browser that started it: only that browser holds a cookie carrying
|
|
1779
|
+
// the attempt's state, so the callback URL completes nowhere else. Each attempt has its own cookie,
|
|
1780
|
+
// so a sign-in in another tab doesn't displace it. The name is a digest and the value is encoded
|
|
1781
|
+
// because the strategy owns the state's format.
|
|
1782
|
+
function oidcStateCookieName(state: string): string {
|
|
1783
|
+
return `sixb_oidc_${createHash("sha256").update(state).digest("base64url").slice(0, 22)}`
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
function oidcSignInRedirect(
|
|
1787
|
+
request: Request,
|
|
1788
|
+
host: SixbHostView,
|
|
1789
|
+
result: OidcStartSignInResult
|
|
1790
|
+
): Response {
|
|
1791
|
+
const response = redirectResponse(result.redirectTo)
|
|
1792
|
+
response.headers.append(
|
|
1793
|
+
"set-cookie",
|
|
1794
|
+
callbackCookieHeader({
|
|
1795
|
+
request,
|
|
1796
|
+
host,
|
|
1797
|
+
name: oidcStateCookieName(result.state),
|
|
1798
|
+
value: encodeURIComponent(result.state),
|
|
1799
|
+
maxAgeSeconds: Math.max(0, Math.floor((result.expiresAt.getTime() - Date.now()) / 1000)),
|
|
1800
|
+
})
|
|
1801
|
+
)
|
|
1802
|
+
return response
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1805
|
+
function matchesOidcStateCookie(request: Request, state: string): boolean {
|
|
1806
|
+
const held = getCookie(request, oidcStateCookieName(state))
|
|
1807
|
+
if (!held) return false
|
|
1808
|
+
const expected = Buffer.from(encodeURIComponent(state))
|
|
1809
|
+
const provided = Buffer.from(held)
|
|
1810
|
+
return expected.length === provided.length && timingSafeEqual(expected, provided)
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1753
1813
|
function bearerTokensBody(
|
|
1754
1814
|
tokens: { readonly accessToken: string; readonly refreshToken: string },
|
|
1755
1815
|
bearer: { readonly accessExpiresAt: Date },
|
|
@@ -1948,6 +2008,11 @@ function authSessionBody(
|
|
|
1948
2008
|
}
|
|
1949
2009
|
}
|
|
1950
2010
|
|
|
2011
|
+
/** No session. Says whether auth is on, so a browser shell knows whether to ask for sign-in. */
|
|
2012
|
+
function signedOutSessionResponse(host: SixbHostView): Response {
|
|
2013
|
+
return jsonResponse({ authenticated: false as const, authEnabled: host.auth.isEnabled() }, 200)
|
|
2014
|
+
}
|
|
2015
|
+
|
|
1951
2016
|
function authSessionJsonResponse(
|
|
1952
2017
|
body: AuthenticatedAuthSessionResponse,
|
|
1953
2018
|
setCookies: readonly string[]
|
package/src/routes/datasets.ts
CHANGED
|
@@ -184,32 +184,6 @@ function datasetVersionNotFound(datasetId: string, versionId?: string) {
|
|
|
184
184
|
})
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
function parseColumns(value: string | undefined): readonly string[] | undefined {
|
|
188
|
-
if (!value) return undefined
|
|
189
|
-
|
|
190
|
-
const columns = value
|
|
191
|
-
.split(",")
|
|
192
|
-
.map((column) => column.trim())
|
|
193
|
-
.filter(Boolean)
|
|
194
|
-
|
|
195
|
-
return columns.length > 0 ? columns : undefined
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function resolveColumns(version: DatasetVersion, requested: readonly string[] | undefined) {
|
|
199
|
-
const available = new Set(version.schema.columns.map((column) => column.name))
|
|
200
|
-
const selected = requested ?? version.schema.columns.map((column) => column.name)
|
|
201
|
-
|
|
202
|
-
for (const column of selected) {
|
|
203
|
-
if (!available.has(column)) {
|
|
204
|
-
throw new Error(
|
|
205
|
-
`Dataset '${version.datasetId}' does not have column '${column}' at version '${version.versionId}'`
|
|
206
|
-
)
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return selected
|
|
211
|
-
}
|
|
212
|
-
|
|
213
187
|
async function collectRows(rows: AsyncIterable<Readonly<Record<string, unknown>>>) {
|
|
214
188
|
const collected: Record<string, unknown>[] = []
|
|
215
189
|
for await (const row of rows) {
|
|
@@ -341,29 +315,23 @@ export function registerDatasetRoutes(app: Elysia, host: SixbHostView) {
|
|
|
341
315
|
const { params, query, set } = context
|
|
342
316
|
const sixb = requireRequestSixb(context)
|
|
343
317
|
try {
|
|
344
|
-
requireDataset(sixb, params.datasetId)
|
|
318
|
+
const dataset = requireDataset(sixb, params.datasetId)
|
|
345
319
|
const parsed = DatasetRowsQuerySchema.parse(query)
|
|
346
320
|
const limit = parseLimit(parsed.limit, DEFAULT_ROW_LIMIT, MAX_ROW_LIMIT)
|
|
347
321
|
const offset = parseOffset(parsed.offset)
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
322
|
+
const page = await sixb.datasets.readRows(dataset, {
|
|
323
|
+
versionId: parsed.versionId,
|
|
324
|
+
// An empty `?columns=` reads every column, like omitting it.
|
|
325
|
+
columns: parsed.columns?.length ? parsed.columns : undefined,
|
|
326
|
+
limit,
|
|
327
|
+
offset,
|
|
328
|
+
})
|
|
329
|
+
if (!page) {
|
|
353
330
|
throw datasetVersionNotFound(params.datasetId, parsed.versionId)
|
|
354
331
|
}
|
|
355
332
|
|
|
356
|
-
const
|
|
357
|
-
const
|
|
358
|
-
const rows = await collectRows(
|
|
359
|
-
host.lakeStorage.readRows({
|
|
360
|
-
datasetId: params.datasetId,
|
|
361
|
-
versionId: version.versionId,
|
|
362
|
-
columns: requestedColumns,
|
|
363
|
-
limit,
|
|
364
|
-
offset,
|
|
365
|
-
})
|
|
366
|
-
)
|
|
333
|
+
const { version, columns, redactions } = page
|
|
334
|
+
const rows = await collectRows(page.rows)
|
|
367
335
|
const hasMore =
|
|
368
336
|
version.rowCount === undefined
|
|
369
337
|
? rows.length === limit
|
|
@@ -374,6 +342,7 @@ export function registerDatasetRoutes(app: Elysia, host: SixbHostView) {
|
|
|
374
342
|
versionId: version.versionId,
|
|
375
343
|
version: serializeDatasetVersion(version),
|
|
376
344
|
columns: [...columns],
|
|
345
|
+
...(redactions === undefined ? {} : { redactions }),
|
|
377
346
|
rows,
|
|
378
347
|
count: rows.length,
|
|
379
348
|
limit,
|
package/src/routes/files.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
SYSTEM_PRINCIPAL,
|
|
7
7
|
} from "@sixb/core"
|
|
8
8
|
import { computeBlobDigest, supportsDirectUpload } from "@sixb/core/blob-storage/server"
|
|
9
|
+
import { canonicalMediaType } from "@sixb/core/internal/blob-storage"
|
|
9
10
|
import { createFileUploadId, createUploadExpiresAt } from "@sixb/core/internal/storage"
|
|
10
11
|
import { type FileUploadSession, FileUploadSessionError } from "@sixb/core/storage"
|
|
11
12
|
import type { Elysia } from "elysia"
|
|
@@ -72,7 +73,8 @@ export function registerFileRoutes(app: Elysia, host: SixbHostView) {
|
|
|
72
73
|
const fileRef = await host.blobStorage.put({
|
|
73
74
|
body: file,
|
|
74
75
|
fileName: file.name || undefined,
|
|
75
|
-
|
|
76
|
+
// Bun derives the part's type from the file name; keep it only if it is well-formed.
|
|
77
|
+
mediaType: canonicalMediaType(file.type) ?? undefined,
|
|
76
78
|
logicalPath: logicalPath ?? undefined,
|
|
77
79
|
})
|
|
78
80
|
|
package/src/routes/models.ts
CHANGED
|
@@ -10,6 +10,9 @@ async function serializeLanguageModel(entry: LanguageModelEntry, defaultEntry: L
|
|
|
10
10
|
provider: entry.provider,
|
|
11
11
|
modelId: entry.modelId,
|
|
12
12
|
isDefault: entry.provider === defaultEntry.provider && entry.modelId === defaultEntry.modelId,
|
|
13
|
+
...(entry.model.defaultReasoning === undefined
|
|
14
|
+
? {}
|
|
15
|
+
: { defaultReasoning: entry.model.defaultReasoning }),
|
|
13
16
|
}
|
|
14
17
|
}
|
|
15
18
|
|
package/src/routes/objects.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
ExpandedObjectRow,
|
|
13
13
|
ObjectRow,
|
|
14
14
|
ObjectRowLinks,
|
|
15
|
+
Redactions,
|
|
15
16
|
} from "@sixb/core/storage"
|
|
16
17
|
import type { Elysia } from "elysia"
|
|
17
18
|
import { ZodError, z } from "zod"
|
|
@@ -62,6 +63,7 @@ function serializeObject(row: {
|
|
|
62
63
|
primaryId: string
|
|
63
64
|
objectTypeId: string
|
|
64
65
|
properties: Record<string, unknown>
|
|
66
|
+
redactions?: Redactions
|
|
65
67
|
createdAt: Date
|
|
66
68
|
updatedAt: Date
|
|
67
69
|
}) {
|
|
@@ -70,6 +72,7 @@ function serializeObject(row: {
|
|
|
70
72
|
primaryId: row.primaryId,
|
|
71
73
|
objectTypeId: row.objectTypeId,
|
|
72
74
|
properties: row.properties,
|
|
75
|
+
...(row.redactions === undefined ? {} : { redactions: row.redactions }),
|
|
73
76
|
createdAt: toIsoString(row.createdAt),
|
|
74
77
|
updatedAt: toIsoString(row.updatedAt),
|
|
75
78
|
}
|
|
@@ -252,8 +255,15 @@ async function searchObjects(
|
|
|
252
255
|
input: { kind: "start", objectTypeId: objectType.id },
|
|
253
256
|
},
|
|
254
257
|
}
|
|
255
|
-
|
|
256
|
-
|
|
258
|
+
try {
|
|
259
|
+
const result = await sixb.objects.executeQuery({ query: objectQuery })
|
|
260
|
+
return result.objects
|
|
261
|
+
} catch (error) {
|
|
262
|
+
// Default text fields the caller cannot read are skipped; a type left with none denies
|
|
263
|
+
// its search. Global search covers what the caller can read, so it matches nothing there.
|
|
264
|
+
if (error instanceof AuthorizationError) return []
|
|
265
|
+
throw error
|
|
266
|
+
}
|
|
257
267
|
})
|
|
258
268
|
)
|
|
259
269
|
|
package/src/routes/project.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { accessTokenSecurityRequirement } from "../auth/access-token-boundary"
|
|
|
4
4
|
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
5
5
|
import { ProjectInfoResponseSchema } from "../schemas/project"
|
|
6
6
|
export function registerProjectRoutes(app: Elysia, host: SixbHostView) {
|
|
7
|
-
|
|
7
|
+
const project = { id: host.id, locale: host.locale, timeZone: host.timeZone }
|
|
8
|
+
return app.get("/api/project", async () => project, {
|
|
8
9
|
response: { 200: ProjectInfoResponseSchema },
|
|
9
10
|
detail: {
|
|
10
11
|
summary: "Get current project metadata",
|
package/src/routes/workflows.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from "@sixb/core"
|
|
9
9
|
import { publishAgentRunCancel } from "@sixb/core/internal/agents"
|
|
10
10
|
import { createSixbError, toSixbFailure } from "@sixb/core/internal/errors"
|
|
11
|
+
import { assertValidFileRefs } from "@sixb/core/internal/ontology"
|
|
11
12
|
import type { Sixb, WorkflowRunView } from "@sixb/core/internal/request-execution"
|
|
12
13
|
import {
|
|
13
14
|
snapshotWorkflowInterventionResponse,
|
|
@@ -731,6 +732,10 @@ export function registerWorkflowRoutes(app: Elysia, host: SixbHostView) {
|
|
|
731
732
|
value: parsedBody.response,
|
|
732
733
|
valueTypesById: host.definitions.ontology.getValueTypesById(),
|
|
733
734
|
})
|
|
735
|
+
assertValidFileRefs(
|
|
736
|
+
parsedBody.response,
|
|
737
|
+
`Workflow "${workflow.id}" intervention "${node.intervention.id}" response`
|
|
738
|
+
)
|
|
734
739
|
|
|
735
740
|
const submitted = await storage.submit({
|
|
736
741
|
projectId: host.id,
|
package/src/routes/ws/events.ts
CHANGED
|
@@ -95,7 +95,7 @@ export function registerEventStreamRoutes(app: Elysia, server: SixbServer) {
|
|
|
95
95
|
return app.ws("/ws/events", {
|
|
96
96
|
async open(ws) {
|
|
97
97
|
// Any authenticated principal may connect; events are filtered per-event
|
|
98
|
-
// by grants as they stream (see `
|
|
98
|
+
// by grants as they stream (see `view` below).
|
|
99
99
|
const state: EventSocketState = {
|
|
100
100
|
replayFrom: null,
|
|
101
101
|
initialized: Promise.resolve(),
|
|
@@ -155,8 +155,10 @@ export function registerEventStreamRoutes(app: Elysia, server: SixbServer) {
|
|
|
155
155
|
matches: (event) =>
|
|
156
156
|
(!filter.topic || event.topic === filter.topic) &&
|
|
157
157
|
(!filter.types?.length || filter.types.includes(event.type)) &&
|
|
158
|
-
eventMatchesScope(event, filter)
|
|
159
|
-
|
|
158
|
+
eventMatchesScope(event, filter),
|
|
159
|
+
// The execution facade owns per-event visibility: it withholds events the caller
|
|
160
|
+
// cannot view and omits marked properties the caller is not cleared for.
|
|
161
|
+
view: (event) => sixb.events.readable(event),
|
|
160
162
|
replay: replayFrom
|
|
161
163
|
? {
|
|
162
164
|
afterCursor: replayFrom.afterCursor,
|
|
@@ -29,6 +29,11 @@ export interface HubSource<T extends HubRecord> {
|
|
|
29
29
|
/** One socket's view of the stream. */
|
|
30
30
|
export interface HubSubscription<T extends HubRecord> {
|
|
31
31
|
matches(record: T): boolean
|
|
32
|
+
/**
|
|
33
|
+
* The matching record as this socket may read it, or `undefined` to withhold it. It keeps the
|
|
34
|
+
* record's cursor. Omit to deliver matching records unchanged.
|
|
35
|
+
*/
|
|
36
|
+
view?(record: T): T | undefined
|
|
32
37
|
/** Replays retained records after `afterCursor` (or from the oldest) before live ones. */
|
|
33
38
|
readonly replay?: {
|
|
34
39
|
readonly afterCursor: string | undefined
|
|
@@ -174,9 +179,10 @@ export class SubscriptionHub<T extends HubRecord> {
|
|
|
174
179
|
private deliverLive(records: readonly T[]): void {
|
|
175
180
|
for (const state of this.clients.values()) {
|
|
176
181
|
for (const record of records) {
|
|
177
|
-
|
|
178
|
-
if (
|
|
179
|
-
|
|
182
|
+
const visible = visibleRecord(state.subscription, record)
|
|
183
|
+
if (!visible) continue
|
|
184
|
+
if (state.catchingUp) this.enqueuePendingLive(state, visible)
|
|
185
|
+
else this.enqueue(state, visible)
|
|
180
186
|
}
|
|
181
187
|
}
|
|
182
188
|
}
|
|
@@ -197,8 +203,9 @@ export class SubscriptionHub<T extends HubRecord> {
|
|
|
197
203
|
if (state.pendingCursors.has(record.cursor)) {
|
|
198
204
|
state.replayedPendingCursors.add(record.cursor)
|
|
199
205
|
}
|
|
200
|
-
|
|
201
|
-
if (!
|
|
206
|
+
const visible = visibleRecord(state.subscription, record)
|
|
207
|
+
if (!visible) continue
|
|
208
|
+
if (!(await this.enqueueReplay(state, visible))) return
|
|
202
209
|
}
|
|
203
210
|
if (state.closed) return
|
|
204
211
|
afterCursor = page.cursor ?? afterCursor
|
|
@@ -360,6 +367,14 @@ export class SubscriptionHub<T extends HubRecord> {
|
|
|
360
367
|
}
|
|
361
368
|
}
|
|
362
369
|
|
|
370
|
+
function visibleRecord<T extends HubRecord>(
|
|
371
|
+
subscription: HubSubscription<T>,
|
|
372
|
+
record: T
|
|
373
|
+
): T | undefined {
|
|
374
|
+
if (!subscription.matches(record)) return undefined
|
|
375
|
+
return subscription.view ? subscription.view(record) : record
|
|
376
|
+
}
|
|
377
|
+
|
|
363
378
|
function hasQueueCapacity(state: ClientState<HubRecord>, bytes: number): boolean {
|
|
364
379
|
return (
|
|
365
380
|
state.queue.length + state.pendingLive.length < MAX_CLIENT_RECORDS &&
|
package/src/schemas/agents.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MAX_AGENT_CONTEXT_ENTRIES } from "@sixb/core"
|
|
2
|
+
import { MAX_AGENT_CONTEXT_LABEL_LENGTH } from "@sixb/core/agents/context"
|
|
2
3
|
import {
|
|
3
4
|
AGENT_RUN_DIAGNOSTIC_CODES,
|
|
4
5
|
AGENT_RUN_FAILURE_CODES,
|
|
@@ -9,7 +10,7 @@ import {
|
|
|
9
10
|
import { z } from "zod"
|
|
10
11
|
import { AiCostSummarySchema } from "./ai-accounting"
|
|
11
12
|
import { AiUsageSummarySchema } from "./ai-usage"
|
|
12
|
-
import { JsonValueSchema, sixbFailureSchema } from "./common"
|
|
13
|
+
import { ErrorResponseSchema, JsonValueSchema, sixbFailureSchema } from "./common"
|
|
13
14
|
import { FileRefSchema } from "./files"
|
|
14
15
|
import { LanguageModelRefSchema, ModelReasoningSchema } from "./models"
|
|
15
16
|
|
|
@@ -44,6 +45,12 @@ export const AgentObjectContextSchema = z.object({
|
|
|
44
45
|
objectTypeId: z.string().min(1),
|
|
45
46
|
primaryId: z.string().min(1),
|
|
46
47
|
}),
|
|
48
|
+
label: z
|
|
49
|
+
.string()
|
|
50
|
+
.min(1)
|
|
51
|
+
.max(MAX_AGENT_CONTEXT_LABEL_LENGTH)
|
|
52
|
+
.optional()
|
|
53
|
+
.describe("Shown in the chat instead of the object's title. Never sent to the model."),
|
|
47
54
|
})
|
|
48
55
|
|
|
49
56
|
export const AgentAppStateContextSchema = z.object({
|
|
@@ -175,8 +182,14 @@ const AgentToolCallErrorSchema = AgentToolCallBaseSchema.extend({
|
|
|
175
182
|
errorText: z.string(),
|
|
176
183
|
})
|
|
177
184
|
|
|
185
|
+
/** The user asked to continue an answer cut short; Sixb writes what the model reads. */
|
|
186
|
+
const AgentContinuationPartSchema = z.object({
|
|
187
|
+
type: z.literal("continuation"),
|
|
188
|
+
})
|
|
189
|
+
|
|
178
190
|
export const AgentMessagePartSchema = z.union([
|
|
179
191
|
AgentTextPartSchema,
|
|
192
|
+
AgentContinuationPartSchema,
|
|
180
193
|
AgentReasoningPartSchema,
|
|
181
194
|
AgentStepStartPartSchema,
|
|
182
195
|
AgentFilePartSchema,
|
|
@@ -189,7 +202,7 @@ export const AgentMessagePartSchema = z.union([
|
|
|
189
202
|
export const AgentRunDiagnosticSchema = z.object({
|
|
190
203
|
code: z.enum(AGENT_RUN_DIAGNOSTIC_CODES),
|
|
191
204
|
severity: z.enum(["warning", "error"]),
|
|
192
|
-
scope: z.
|
|
205
|
+
scope: z.enum(["output", "run"]),
|
|
193
206
|
path: z.string().optional(),
|
|
194
207
|
message: z.string(),
|
|
195
208
|
})
|
|
@@ -234,15 +247,27 @@ export const AgentMessageListResponseSchema = z.object({
|
|
|
234
247
|
|
|
235
248
|
export const PostAgentMessageBodySchema = z
|
|
236
249
|
.object({
|
|
237
|
-
|
|
250
|
+
/** Required unless `continue` is set. */
|
|
251
|
+
text: z.string().trim().min(1).optional(),
|
|
252
|
+
/** Continue the previous answer after it reached the turn limit, without text of its own. */
|
|
253
|
+
continue: z.literal(true).optional(),
|
|
238
254
|
model: LanguageModelRefSchema.optional(),
|
|
239
255
|
reasoning: ModelReasoningSchema.optional(),
|
|
256
|
+
/** IANA time zone of the person asking. The Agent presents dates and times in it. */
|
|
257
|
+
timeZone: z.string().trim().min(1).max(100).optional(),
|
|
258
|
+
/** BCP 47 language of the person asking. */
|
|
259
|
+
locale: z.string().trim().min(1).max(100).optional(),
|
|
240
260
|
attachments: z.array(FileRefSchema).optional(),
|
|
241
261
|
context: z.array(AgentContextEntryInputSchema).max(MAX_AGENT_CONTEXT_ENTRIES).optional(),
|
|
242
262
|
messageId: z.string().trim().min(1).optional(),
|
|
243
263
|
})
|
|
244
264
|
.strict()
|
|
245
265
|
|
|
266
|
+
/** A refused message request, with the stable code of the reason, such as `invalid_locale`. */
|
|
267
|
+
export const AgentRequestErrorResponseSchema = ErrorResponseSchema.extend({
|
|
268
|
+
code: z.string().optional(),
|
|
269
|
+
})
|
|
270
|
+
|
|
246
271
|
export const CancelAgentRunBodySchema = z.object({
|
|
247
272
|
runId: z.string().trim().min(1),
|
|
248
273
|
})
|
package/src/schemas/auth.ts
CHANGED
|
@@ -274,6 +274,11 @@ export const RevokeAuthInvitationResponseSchema = z.object({
|
|
|
274
274
|
export const AuthSessionResponseSchema = z.union([
|
|
275
275
|
z.object({
|
|
276
276
|
authenticated: z.literal(false),
|
|
277
|
+
/**
|
|
278
|
+
* False when the project runs without auth: every request is allowed and there is nothing to
|
|
279
|
+
* sign in to. Browser shells read it instead of being told by the server that serves them.
|
|
280
|
+
*/
|
|
281
|
+
authEnabled: z.boolean(),
|
|
277
282
|
}),
|
|
278
283
|
z.object({
|
|
279
284
|
authenticated: z.literal(true),
|
package/src/schemas/common.ts
CHANGED
|
@@ -13,6 +13,9 @@ export function codedErrorResponseSchema<
|
|
|
13
13
|
})
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/** Values omitted because the caller lacks a clearance for their markings. */
|
|
17
|
+
export const RedactionsSchema = z.record(z.object({ reason: z.literal("missing_clearance") }))
|
|
18
|
+
|
|
16
19
|
export const SuccessResponseSchema = z.object({ success: z.boolean() })
|
|
17
20
|
|
|
18
21
|
/** The canonical `Principal` shape from `@sixb/core`. */
|
package/src/schemas/datasets.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod"
|
|
2
|
+
import { RedactionsSchema } from "./common"
|
|
2
3
|
|
|
3
4
|
export const DatasetParamsSchema = z.object({
|
|
4
5
|
datasetId: z.string().min(1),
|
|
@@ -12,9 +13,27 @@ export const DatasetVersionsQuerySchema = z.object({
|
|
|
12
13
|
limit: z.string().optional(),
|
|
13
14
|
})
|
|
14
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Elysia's query parser splits any comma-separated value into an array before validation, and
|
|
18
|
+
* pushes a repeated key's value into the existing array as-is. `?columns=id`, `?columns=id,title`,
|
|
19
|
+
* `?columns=id&columns=title` and `?columns=x&columns=id,title` therefore arrive as a string, a
|
|
20
|
+
* flat array, a flat array, and a nested array. All of them name the same thing: a column list.
|
|
21
|
+
*/
|
|
22
|
+
const QueryStringListSchema = z.preprocess(flattenQueryStringList, z.array(z.string()))
|
|
23
|
+
|
|
24
|
+
function flattenQueryStringList(value: unknown): unknown {
|
|
25
|
+
if (typeof value !== "string" && !Array.isArray(value)) return value
|
|
26
|
+
const items = [value].flat(Number.POSITIVE_INFINITY)
|
|
27
|
+
if (!items.every((item) => typeof item === "string")) return value
|
|
28
|
+
return items
|
|
29
|
+
.flatMap((item) => item.split(","))
|
|
30
|
+
.map((item) => item.trim())
|
|
31
|
+
.filter(Boolean)
|
|
32
|
+
}
|
|
33
|
+
|
|
15
34
|
export const DatasetRowsQuerySchema = z.object({
|
|
16
35
|
versionId: z.string().optional(),
|
|
17
|
-
columns:
|
|
36
|
+
columns: QueryStringListSchema.optional(),
|
|
18
37
|
limit: z.string().optional(),
|
|
19
38
|
offset: z.string().optional(),
|
|
20
39
|
})
|
|
@@ -99,7 +118,10 @@ export const DatasetRowsResponseSchema = z.object({
|
|
|
99
118
|
datasetId: z.string(),
|
|
100
119
|
versionId: z.string(),
|
|
101
120
|
version: DatasetVersionSchema,
|
|
121
|
+
/** Returned columns. Redacted columns are left out. */
|
|
102
122
|
columns: z.array(z.string()),
|
|
123
|
+
/** Columns omitted because the caller lacks a clearance for their markings. */
|
|
124
|
+
redactions: RedactionsSchema.optional(),
|
|
103
125
|
rows: z.array(z.record(z.unknown())),
|
|
104
126
|
count: z.number(),
|
|
105
127
|
limit: z.number(),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DomainEvent } from "@sixb/core"
|
|
2
2
|
import { z } from "zod"
|
|
3
|
-
import { JsonNullSchema, JsonValueSchema } from "./common"
|
|
3
|
+
import { JsonNullSchema, JsonValueSchema, RedactionsSchema } from "./common"
|
|
4
4
|
|
|
5
5
|
const PropertyChangeSchema = z.discriminatedUnion("operation", [
|
|
6
6
|
z.object({ operation: z.literal("created"), after: JsonValueSchema }),
|
|
@@ -22,11 +22,13 @@ const ObjectMutationPayloadSchema = z.object({
|
|
|
22
22
|
primaryId: z.string(),
|
|
23
23
|
properties: z.record(JsonValueSchema),
|
|
24
24
|
propertyChanges: PropertyChangesSchema,
|
|
25
|
+
redactions: RedactionsSchema.optional(),
|
|
25
26
|
})
|
|
26
27
|
const ObjectDeletedPayloadSchema = z.object({
|
|
27
28
|
objectTypeId: z.string(),
|
|
28
29
|
primaryId: z.string(),
|
|
29
30
|
propertyChanges: PropertyChangesSchema,
|
|
31
|
+
redactions: RedactionsSchema.optional(),
|
|
30
32
|
})
|
|
31
33
|
const LinkSubjectSchema = z.object({
|
|
32
34
|
sourceTypeId: z.string(),
|