@sixb/server 0.1.17 → 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.
Files changed (110) hide show
  1. package/README.md +3 -3
  2. package/dist/actions/serialize.d.ts +7 -0
  3. package/dist/actions/serialize.d.ts.map +1 -0
  4. package/dist/auth/experience.d.ts +5 -1
  5. package/dist/auth/experience.d.ts.map +1 -1
  6. package/dist/files/content.d.ts +0 -1
  7. package/dist/files/content.d.ts.map +1 -1
  8. package/dist/index.js +812 -769
  9. package/dist/index.js.map +32 -31
  10. package/dist/routes/action-runs.d.ts +11 -13
  11. package/dist/routes/action-runs.d.ts.map +1 -1
  12. package/dist/routes/actions.d.ts +44 -13
  13. package/dist/routes/actions.d.ts.map +1 -1
  14. package/dist/routes/agent-api-gateway.d.ts.map +1 -1
  15. package/dist/routes/agents.d.ts +67 -47
  16. package/dist/routes/agents.d.ts.map +1 -1
  17. package/dist/routes/auth.d.ts +3 -2
  18. package/dist/routes/auth.d.ts.map +1 -1
  19. package/dist/routes/connector-connection-runs.d.ts +21 -21
  20. package/dist/routes/connector-connections.d.ts +8 -8
  21. package/dist/routes/connectors.d.ts +2 -2
  22. package/dist/routes/datasets.d.ts +9 -6
  23. package/dist/routes/datasets.d.ts.map +1 -1
  24. package/dist/routes/events.d.ts +4 -4
  25. package/dist/routes/files.d.ts +15 -12
  26. package/dist/routes/files.d.ts.map +1 -1
  27. package/dist/routes/models.d.ts +1 -0
  28. package/dist/routes/models.d.ts.map +1 -1
  29. package/dist/routes/objects.d.ts +21 -4
  30. package/dist/routes/objects.d.ts.map +1 -1
  31. package/dist/routes/ontology.d.ts +6 -6
  32. package/dist/routes/pipelines.d.ts +16 -16
  33. package/dist/routes/project.d.ts +2 -0
  34. package/dist/routes/project.d.ts.map +1 -1
  35. package/dist/routes/projections.d.ts +49 -49
  36. package/dist/routes/syncs.d.ts +10 -10
  37. package/dist/routes/webhook-runs.d.ts +2 -2
  38. package/dist/routes/workflows.d.ts +51 -48
  39. package/dist/routes/workflows.d.ts.map +1 -1
  40. package/dist/routes/ws/events.d.ts +6 -9
  41. package/dist/routes/ws/events.d.ts.map +1 -1
  42. package/dist/routes/ws/subscription-hub.d.ts +5 -0
  43. package/dist/routes/ws/subscription-hub.d.ts.map +1 -1
  44. package/dist/schemas/actions.d.ts +100 -84
  45. package/dist/schemas/actions.d.ts.map +1 -1
  46. package/dist/schemas/agents.d.ts +242 -143
  47. package/dist/schemas/agents.d.ts.map +1 -1
  48. package/dist/schemas/ai-accounting.d.ts +10 -10
  49. package/dist/schemas/ai-limits.d.ts +10 -10
  50. package/dist/schemas/auth.d.ts +7 -0
  51. package/dist/schemas/auth.d.ts.map +1 -1
  52. package/dist/schemas/common.d.ts +8 -0
  53. package/dist/schemas/common.d.ts.map +1 -1
  54. package/dist/schemas/connectors.d.ts +8 -8
  55. package/dist/schemas/datasets.d.ts +58 -43
  56. package/dist/schemas/datasets.d.ts.map +1 -1
  57. package/dist/schemas/event-payloads.d.ts +39 -0
  58. package/dist/schemas/event-payloads.d.ts.map +1 -1
  59. package/dist/schemas/events.d.ts +24 -24
  60. package/dist/schemas/events.d.ts.map +1 -1
  61. package/dist/schemas/files.d.ts +5 -5
  62. package/dist/schemas/files.d.ts.map +1 -1
  63. package/dist/schemas/models.d.ts +10 -0
  64. package/dist/schemas/models.d.ts.map +1 -1
  65. package/dist/schemas/objects.d.ts +32 -0
  66. package/dist/schemas/objects.d.ts.map +1 -1
  67. package/dist/schemas/ontology.d.ts +40 -40
  68. package/dist/schemas/pipelines.d.ts +92 -92
  69. package/dist/schemas/project.d.ts +8 -0
  70. package/dist/schemas/project.d.ts.map +1 -1
  71. package/dist/schemas/projections.d.ts +290 -290
  72. package/dist/schemas/syncs.d.ts +34 -34
  73. package/dist/schemas/webhook-runs.d.ts +8 -8
  74. package/dist/schemas/workflows.d.ts +177 -160
  75. package/dist/schemas/workflows.d.ts.map +1 -1
  76. package/dist/server.d.ts +1 -0
  77. package/dist/server.d.ts.map +1 -1
  78. package/dist/utils/http.d.ts.map +1 -1
  79. package/dist/utils/request-body.d.ts +20 -6
  80. package/dist/utils/request-body.d.ts.map +1 -1
  81. package/package.json +6 -5
  82. package/src/actions/serialize.ts +55 -0
  83. package/src/auth/experience.ts +20 -2
  84. package/src/files/content.ts +43 -88
  85. package/src/routes/action-runs.ts +1 -54
  86. package/src/routes/actions.ts +26 -8
  87. package/src/routes/agent-api-gateway.ts +18 -42
  88. package/src/routes/agents.ts +29 -9
  89. package/src/routes/auth.ts +84 -19
  90. package/src/routes/datasets.ts +12 -43
  91. package/src/routes/files.ts +18 -64
  92. package/src/routes/models.ts +3 -0
  93. package/src/routes/objects.ts +12 -2
  94. package/src/routes/project.ts +2 -1
  95. package/src/routes/workflows.ts +5 -0
  96. package/src/routes/ws/events.ts +7 -15
  97. package/src/routes/ws/subscription-hub.ts +20 -5
  98. package/src/schemas/actions.ts +21 -18
  99. package/src/schemas/agents.ts +28 -3
  100. package/src/schemas/auth.ts +5 -0
  101. package/src/schemas/common.ts +3 -0
  102. package/src/schemas/datasets.ts +23 -1
  103. package/src/schemas/event-payloads.ts +3 -1
  104. package/src/schemas/files.ts +7 -1
  105. package/src/schemas/models.ts +2 -0
  106. package/src/schemas/objects.ts +13 -0
  107. package/src/schemas/project.ts +4 -0
  108. package/src/server.ts +23 -4
  109. package/src/utils/http.ts +2 -0
  110. package/src/utils/request-body.ts +55 -6
@@ -1,6 +1,17 @@
1
- import { AgentRequestError, type AgentRunView, type FileRef, type SixbHostView } from "@sixb/core"
2
- import { publishAgentRunCancel, publishAgentRunFinished } from "@sixb/core/internal/agents"
1
+ import {
2
+ AgentRequestError,
3
+ type AgentRequestErrorCode,
4
+ type AgentRunView,
5
+ type FileRef,
6
+ type SixbHostView,
7
+ } from "@sixb/core"
8
+ import {
9
+ isRetryableAgentRun,
10
+ publishAgentRunCancel,
11
+ publishAgentRunFinished,
12
+ } from "@sixb/core/internal/agents"
3
13
  import { agentRunStreamId } from "@sixb/core/internal/agents/streams"
14
+ import { resolveFileRefAtPath } from "@sixb/core/internal/blob-storage"
4
15
  import {
5
16
  type AgentContextCheckpointRecord,
6
17
  type AgentMessageRecord,
@@ -19,7 +30,6 @@ import {
19
30
  createFileContentResponse,
20
31
  fileContentGetResponses,
21
32
  fileContentHeadResponses,
22
- resolveFileRefAtPath,
23
33
  } from "../files/content"
24
34
  import { SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT } from "../openapi/security"
25
35
  import { OPENAPI_TAGS } from "../openapi/tags"
@@ -29,6 +39,7 @@ import {
29
39
  AgentMessageListResponseSchema,
30
40
  AgentMessageSchema,
31
41
  AgentMessagesQuerySchema,
42
+ AgentRequestErrorResponseSchema,
32
43
  AgentRunListQuerySchema,
33
44
  AgentRunListResponseSchema,
34
45
  AgentRunParamsSchema,
@@ -170,7 +181,9 @@ async function publishQueuedRunCancellation(
170
181
  function handleAgentRouteError(
171
182
  error: unknown,
172
183
  set: { status?: number | string; headers?: unknown }
173
- ): ReturnType<typeof handleRouteError> {
184
+ ):
185
+ | ReturnType<typeof handleRouteError>
186
+ | { readonly error: string; readonly code: AgentRequestErrorCode } {
174
187
  // A duplicate id is a conflict, not a bad request. Map it to a generic 409 rather than echoing the
175
188
  // provider's raw message (which leaks the id, project, and storage prefix).
176
189
  if (error instanceof AgentStorageError && error.code === "duplicate_id") {
@@ -203,12 +216,16 @@ function handleAgentRouteError(
203
216
  case "invalid_sandbox_params":
204
217
  case "agent_selector_removed":
205
218
  case "invalid_context":
219
+ case "invalid_attachment":
206
220
  case "invalid_model_selection":
221
+ case "invalid_locale":
222
+ case "invalid_message":
207
223
  case "model_not_found":
208
224
  set.status = 400
209
225
  break
210
226
  }
211
- return { error: error.message }
227
+ // The code lets clients react without parsing the English message.
228
+ return { error: error.message, code: error.code }
212
229
  }
213
230
 
214
231
  return handleRouteError(error, set)
@@ -594,8 +611,11 @@ export function registerAgentRoutes(app: Elysia, host: SixbHostView) {
594
611
  const requestInput = {
595
612
  threadId: thread.id,
596
613
  text: parsed.text,
614
+ continue: parsed.continue,
597
615
  model: parsed.model,
598
616
  reasoning: parsed.reasoning,
617
+ timeZone: parsed.timeZone,
618
+ locale: parsed.locale,
599
619
  attachments: parsed.attachments as readonly FileRef[] | undefined,
600
620
  context: parsed.context,
601
621
  messageId: parsed.messageId,
@@ -615,7 +635,7 @@ export function registerAgentRoutes(app: Elysia, host: SixbHostView) {
615
635
  body: PostAgentMessageBodySchema,
616
636
  response: {
617
637
  202: PostAgentMessageResponseSchema,
618
- 400: ErrorResponseSchema,
638
+ 400: AgentRequestErrorResponseSchema,
619
639
  403: ErrorResponseSchema,
620
640
  404: ErrorResponseSchema,
621
641
  409: ErrorResponseSchema,
@@ -747,9 +767,9 @@ export function registerAgentRoutes(app: Elysia, host: SixbHostView) {
747
767
  set.status = 404
748
768
  return { error: "Agent run not found" }
749
769
  }
750
- if (failedRun.status !== "failed") {
770
+ if (!isRetryableAgentRun(failedRun)) {
751
771
  set.status = 409
752
- return { error: "Only failed agent runs can be retried" }
772
+ return { error: "Only failed or interrupted agent runs can be retried" }
753
773
  }
754
774
 
755
775
  const { run } = await sixb.agent.runs.retry(failedRun.id)
@@ -773,7 +793,7 @@ export function registerAgentRoutes(app: Elysia, host: SixbHostView) {
773
793
  501: ErrorResponseSchema,
774
794
  },
775
795
  detail: {
776
- summary: "Retry a failed agent run",
796
+ summary: "Retry a failed or interrupted agent run",
777
797
  tags: [OPENAPI_TAGS.agentRuns.name],
778
798
  operationId: "retryAgentRun",
779
799
  security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT,
@@ -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 SixbAuthExperienceOptions,
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?: SixbAuthExperienceOptions
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 jsonResponse({ authenticated: false as const }, 200)
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 jsonResponse({ authenticated: false as const }, 200)
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: accessTokenSecurityRequirement("createAuthPersonalAccessToken"),
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: accessTokenSecurityRequirement("createAuthServiceAccountAccessToken"),
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
- magicLinkPendingCookieHeader({
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 redirectResponse(result.redirectTo)
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 redirectResponse(result.redirectTo)
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
- return sessionCallbackCompletionResponse({
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
- if (error instanceof SignInRefusedError) {
1561
- return htmlMessageResponse(signInRefusalMessage(error), 403, "You can't sign in")
1562
- }
1563
- return htmlMessageResponse("This sign-in attempt could not be completed.", 400)
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 arrives as a cross-site top-level
1674
- // navigation and the cookie must accompany that GET for the fast path to work.
1675
- function magicLinkPendingCookieHeader(params: {
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
- `${MAGIC_LINK_PENDING_COOKIE_NAME}=${params.value}`,
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
- magicLinkPendingCookieHeader({
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[]
@@ -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 version = parsed.versionId
349
- ? await host.lakeStorage.getVersion(params.datasetId, parsed.versionId)
350
- : await host.lakeStorage.getLatestVersion(params.datasetId)
351
-
352
- if (!version) {
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 requestedColumns = parseColumns(parsed.columns)
357
- const columns = resolveColumns(version, requestedColumns)
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,
@@ -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"
@@ -24,7 +25,7 @@ import {
24
25
  SignedFileUploadPartSchema,
25
26
  } from "../schemas/files"
26
27
  import { handleRouteError, unconfiguredStorageResponse } from "../utils/http"
27
- import { RequestBodyTooLargeError, readRequestBodyWithLimit } from "../utils/request-body"
28
+ import { readRequestBodyWithLimit } from "../utils/request-body"
28
29
  // The simple-upload ceiling lives in @sixb/core so the client staged-switch
29
30
  // threshold and this server limit stay a single source of truth. The body limit
30
31
  // adds headroom for multipart/form-data encoding overhead on the `POST /api/files`
@@ -39,16 +40,14 @@ export function registerFileRoutes(app: Elysia, host: SixbHostView) {
39
40
  "/api/files",
40
41
  async ({ request, set }) => {
41
42
  try {
42
- const requestSizeError = requestSizeLimitError(
43
+ const bytes = await readRequestBodyWithLimit(
43
44
  request,
44
- 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.`
45
47
  )
46
- if (requestSizeError) {
47
- set.status = 413
48
- return { error: requestSizeError }
49
- }
50
-
51
- const form = await request.formData()
48
+ const form = await new Response(bytes, {
49
+ headers: { "content-type": request.headers.get("content-type") ?? "" },
50
+ }).formData()
52
51
  const file = form.get("file")
53
52
  const logicalPath = form.get("logicalPath")
54
53
 
@@ -72,7 +71,8 @@ export function registerFileRoutes(app: Elysia, host: SixbHostView) {
72
71
  const fileRef = await host.blobStorage.put({
73
72
  body: file,
74
73
  fileName: file.name || undefined,
75
- mediaType: file.type || undefined,
74
+ // Bun derives the part's type from the file name; keep it only if it is well-formed.
75
+ mediaType: canonicalMediaType(file.type) ?? undefined,
76
76
  logicalPath: logicalPath ?? undefined,
77
77
  })
78
78
 
@@ -203,7 +203,10 @@ export function registerFileRoutes(app: Elysia, host: SixbHostView) {
203
203
  return { error: contentLengthSizeError }
204
204
  }
205
205
 
206
- const uploadBytes = readParsedUploadBytes(context)
206
+ const uploadBytes = await readRequestBodyWithLimit(
207
+ request,
208
+ DEFAULT_SIMPLE_FILE_UPLOAD_BYTES
209
+ )
207
210
  if (uploadBytes.byteLength === 0) {
208
211
  set.status = 400
209
212
  return { error: "Expected upload content body." }
@@ -237,18 +240,16 @@ export function registerFileRoutes(app: Elysia, host: SixbHostView) {
237
240
  },
238
241
  {
239
242
  params: FileUploadIdParamsSchema,
240
- // Replace Elysia's default body parser so the octet-stream is read through
241
- // the size-capped streaming reader instead of being fully buffered first.
242
- parse: readCappedUploadBody,
243
- // The cap is enforced during parsing, which is outside the handler's
244
- // try/catch, so map its too-large error to 413 here.
245
- 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",
246
246
  response: {
247
247
  200: SuccessResponseSchema,
248
248
  400: ErrorResponseSchema,
249
249
  404: ErrorResponseSchema,
250
250
  409: ErrorResponseSchema,
251
251
  410: ErrorResponseSchema,
252
+ 413: ErrorResponseSchema,
252
253
  501: ErrorResponseSchema,
253
254
  },
254
255
  detail: {
@@ -496,39 +497,6 @@ function fileUploadResponse(session: FileUploadSession) {
496
497
  }
497
498
  }
498
499
 
499
- // Elysia `parse` hook: reads the staged content stream with a hard size ceiling,
500
- // so an oversized (or chunked, content-length-lying) body is rejected before it
501
- // is fully buffered. Its result becomes `context.body`.
502
- function readCappedUploadBody(context: { request: Request }): Promise<Uint8Array> {
503
- return readRequestBodyWithLimit(context.request, DEFAULT_SIMPLE_FILE_UPLOAD_BYTES)
504
- }
505
-
506
- function readParsedUploadBytes(context: { body?: unknown }): Uint8Array {
507
- return context.body instanceof Uint8Array ? context.body : new Uint8Array(0)
508
- }
509
-
510
- function mapUploadContentError(context: {
511
- error: unknown
512
- set: { status?: number | string }
513
- }): { error: string } | undefined {
514
- const tooLarge = asRequestBodyTooLarge(context.error)
515
- if (tooLarge) {
516
- context.set.status = 413
517
- return { error: tooLarge.message }
518
- }
519
- return undefined
520
- }
521
-
522
- // The cap runs in the `parse` phase, so Elysia surfaces it wrapped in a
523
- // ParseError; the original error is carried on `cause`.
524
- function asRequestBodyTooLarge(error: unknown): RequestBodyTooLargeError | undefined {
525
- if (error instanceof RequestBodyTooLargeError) {
526
- return error
527
- }
528
- const cause = (error as { cause?: unknown } | null | undefined)?.cause
529
- return cause instanceof RequestBodyTooLargeError ? cause : undefined
530
- }
531
-
532
500
  // A non-pending session is terminal; surface which terminal state so the route
533
501
  // boundary maps it to 409. Store lookups already raise `not_found`/`expired`.
534
502
  function terminalSessionError(status: "completed" | "aborted"): FileUploadSessionError {
@@ -647,20 +615,6 @@ function expectedSizeBytesValueError(
647
615
  : null
648
616
  }
649
617
 
650
- function requestSizeLimitError(request: Request, maxSizeBytes: number): string | null {
651
- const value = request.headers.get("content-length")
652
- if (value === null) {
653
- return null
654
- }
655
-
656
- const sizeBytes = Number(value)
657
- if (!Number.isSafeInteger(sizeBytes) || sizeBytes <= maxSizeBytes) {
658
- return null
659
- }
660
-
661
- return `File upload request exceeds the ${maxSizeBytes} byte limit.`
662
- }
663
-
664
618
  function expectedContentLengthError(session: FileUploadSession, request: Request): string | null {
665
619
  if (session.expectedSizeBytes === undefined) {
666
620
  return null
@@ -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
 
@@ -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
- const result = await sixb.objects.executeQuery({ query: objectQuery })
256
- return result.objects
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
 
@@ -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
- return app.get("/api/project", async () => ({ id: host.id }), {
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",
@@ -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,