@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
@@ -23,7 +23,6 @@ const SubscribeSchema = z.object({
23
23
  types: z.array(z.enum(EVENT_TYPES)).optional(),
24
24
  objectTypeId: z.string().optional(),
25
25
  primaryId: z.string().optional(),
26
- actionId: z.string().optional(),
27
26
  runId: z.string().optional(),
28
27
  afterCursor: z.string().optional(),
29
28
  limit: z.number().int().positive().max(500).optional(),
@@ -95,7 +94,7 @@ export function registerEventStreamRoutes(app: Elysia, server: SixbServer) {
95
94
  return app.ws("/ws/events", {
96
95
  async open(ws) {
97
96
  // Any authenticated principal may connect; events are filtered per-event
98
- // by grants as they stream (see `matches` below).
97
+ // by grants as they stream (see `view` below).
99
98
  const state: EventSocketState = {
100
99
  replayFrom: null,
101
100
  initialized: Promise.resolve(),
@@ -155,8 +154,10 @@ export function registerEventStreamRoutes(app: Elysia, server: SixbServer) {
155
154
  matches: (event) =>
156
155
  (!filter.topic || event.topic === filter.topic) &&
157
156
  (!filter.types?.length || filter.types.includes(event.type)) &&
158
- eventMatchesScope(event, filter) &&
159
- sixb.events.canRead(event),
157
+ eventMatchesScope(event, filter),
158
+ // The execution facade owns per-event visibility: it withholds events the caller
159
+ // cannot view and omits marked properties the caller is not cleared for.
160
+ view: (event) => sixb.events.readable(event),
160
161
  replay: replayFrom
161
162
  ? {
162
163
  afterCursor: replayFrom.afterCursor,
@@ -210,17 +211,11 @@ function eventMatchesScope(
210
211
  filter: {
211
212
  readonly objectTypeId?: string
212
213
  readonly primaryId?: string
213
- readonly actionId?: string
214
214
  readonly runId?: string
215
215
  }
216
216
  ): boolean {
217
- const { objectTypeId, primaryId, actionId, runId } = filter
218
- if (
219
- objectTypeId === undefined &&
220
- primaryId === undefined &&
221
- actionId === undefined &&
222
- runId === undefined
223
- ) {
217
+ const { objectTypeId, primaryId, runId } = filter
218
+ if (objectTypeId === undefined && primaryId === undefined && runId === undefined) {
224
219
  return true
225
220
  }
226
221
 
@@ -231,9 +226,6 @@ function eventMatchesScope(
231
226
  if (primaryId !== undefined && scope.primaryId !== primaryId) {
232
227
  return false
233
228
  }
234
- if (actionId !== undefined && scope.actionId !== actionId) {
235
- return false
236
- }
237
229
  if (runId !== undefined && scope.runId !== runId) {
238
230
  return false
239
231
  }
@@ -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
- if (!state.subscription.matches(record)) continue
178
- if (state.catchingUp) this.enqueuePendingLive(state, record)
179
- else this.enqueue(state, record)
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
- if (!state.subscription.matches(record)) continue
201
- if (!(await this.enqueueReplay(state, record))) return
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 &&
@@ -1,10 +1,11 @@
1
+ import { SIXB_ERROR_CODES } from "@sixb/core/internal/errors"
1
2
  import {
2
3
  ACTION_RUN_FAILURE_CODES,
3
4
  ACTION_RUN_PHASES,
4
5
  type ActionRunFailure,
5
6
  } from "@sixb/core/storage"
6
7
  import { z } from "zod"
7
- import { JsonValueSchema, sixbFailureSchema } from "./common"
8
+ import { codedErrorResponseSchema, JsonValueSchema, sixbFailureSchema } from "./common"
8
9
  import { ActionParamSchema } from "./ontology"
9
10
 
10
11
  export const ActionIdParamsSchema = z.object({
@@ -32,12 +33,19 @@ export const RequestActionBodySchema = z.object({
32
33
  runId: z.string().min(1).optional(),
33
34
  })
34
35
 
35
- export const RequestActionResponseSchema = z.object({
36
- runId: z.string(),
37
- queuedAt: z.string(),
38
- jobId: z.string().optional(),
39
- created: z.boolean(),
40
- })
36
+ /** A request reused the run id of a run this server is still executing. */
37
+ export const ActionRunInProgressResponseSchema = codedErrorResponseSchema([
38
+ "action.run_in_progress",
39
+ ])
40
+
41
+ /**
42
+ * An unexpected failure. It can follow a run that started: requesting the same `runId` again
43
+ * returns the run's record if it was written, and runs it again otherwise.
44
+ */
45
+ export const ActionRequestFailedResponseSchema = codedErrorResponseSchema(SIXB_ERROR_CODES)
46
+
47
+ /** The server is stopping and refused the request before starting anything. */
48
+ export const RuntimeStoppingResponseSchema = codedErrorResponseSchema(["runtime.stopping"])
41
49
 
42
50
  export const ActionCatalogItemSchema = z.object({
43
51
  id: z.string(),
@@ -58,13 +66,8 @@ export const ActionDetailSchema = ActionCatalogItemSchema.extend({
58
66
  inputSchema: z.record(z.unknown()),
59
67
  })
60
68
 
61
- export const ActionRunStatusSchema = z.enum([
62
- "queued",
63
- "running",
64
- "succeeded",
65
- "failed",
66
- "cancelled",
67
- ])
69
+ /** How a run ended: a run is recorded once, when it ends. */
70
+ export const ActionRunStatusSchema = z.enum(["succeeded", "failed"])
68
71
 
69
72
  export const ActionRunPhaseSchema = z.enum(ACTION_RUN_PHASES)
70
73
 
@@ -116,10 +119,10 @@ export const ActionRunSummarySchema = z.object({
116
119
  actionId: z.string(),
117
120
  subject: ActionSubjectSchema,
118
121
  status: ActionRunStatusSchema,
119
- phase: ActionRunPhaseSchema.optional(),
120
- queuedAt: z.string(),
121
- startedAt: z.string().optional(),
122
- finishedAt: z.string().optional(),
122
+ /** The last phase the run reached. */
123
+ phase: ActionRunPhaseSchema,
124
+ startedAt: z.string(),
125
+ finishedAt: z.string(),
123
126
  error: ActionRunFailureSchema.optional(),
124
127
  })
125
128
 
@@ -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.literal("output"),
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
- text: z.string().trim().min(1),
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
  })
@@ -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),
@@ -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`. */
@@ -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: z.string().optional(),
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(),
@@ -1,3 +1,4 @@
1
+ import { canonicalMediaType } from "@sixb/core/internal/blob-storage"
1
2
  import { z } from "zod"
2
3
 
3
4
  export const BlobDigestSchema = z.string().regex(/^sha256:[a-f0-9]{64}$/)
@@ -13,7 +14,12 @@ export const FileRefSchema = z.object({
13
14
 
14
15
  export const CreateFileUploadBodySchema = z.object({
15
16
  fileName: z.string().optional(),
16
- mediaType: z.string().optional(),
17
+ mediaType: z
18
+ .string()
19
+ .refine((value) => canonicalMediaType(value) !== null, {
20
+ message: 'Expected a single media type, such as "application/pdf"',
21
+ })
22
+ .optional(),
17
23
  sizeBytes: z.number().int().nonnegative().optional(),
18
24
  digest: BlobDigestSchema.optional(),
19
25
  logicalPath: z.string().optional(),
@@ -29,6 +29,8 @@ export const LanguageModelSchema = LanguageModelRefSchema.extend({
29
29
  contextWindowTokens: z.number().int().positive().optional(),
30
30
  }),
31
31
  reasoningLevels: z.array(z.enum(MODEL_REASONING_LEVELS)),
32
+ /** Reasoning the project applies when a request selects this model without choosing one. */
33
+ defaultReasoning: z.enum(MODEL_REASONING_LEVELS).optional(),
32
34
  })
33
35
 
34
36
  export const ModelCatalogSchema = z.object({
@@ -5,6 +5,7 @@ import {
5
5
  AiUsageLimitErrorResponseSchema,
6
6
  JsonValueSchema,
7
7
  jsonValueOpenApiOverride,
8
+ RedactionsSchema,
8
9
  } from "./common"
9
10
 
10
11
  type OpenApiSchema = NonNullable<
@@ -350,6 +351,7 @@ export const TwinObjectSchema = z.object({
350
351
  primaryId: z.string(),
351
352
  objectTypeId: z.string(),
352
353
  properties: z.record(z.unknown()),
354
+ redactions: RedactionsSchema.optional(),
353
355
  createdAt: z.string(),
354
356
  updatedAt: z.string(),
355
357
  })
@@ -385,6 +387,16 @@ export const ObjectQueryOpenApiSchemas: OpenApiSchemas = {
385
387
  error: { type: "string" },
386
388
  },
387
389
  },
390
+ // Values omitted because the caller lacks a clearance for their markings.
391
+ Redactions: {
392
+ type: "object",
393
+ additionalProperties: {
394
+ type: "object",
395
+ required: ["reason"],
396
+ additionalProperties: false,
397
+ properties: { reason: { type: "string", enum: ["missing_clearance"] } },
398
+ },
399
+ },
388
400
  ObjectQueryObject: {
389
401
  type: "object",
390
402
  required: ["primaryId", "objectTypeId", "properties", "createdAt", "updatedAt"],
@@ -394,6 +406,7 @@ export const ObjectQueryOpenApiSchemas: OpenApiSchemas = {
394
406
  primaryId: { type: "string" },
395
407
  objectTypeId: { type: "string" },
396
408
  properties: { type: "object", additionalProperties: true },
409
+ redactions: { $ref: "#/components/schemas/Redactions" },
397
410
  createdAt: { type: "string" },
398
411
  updatedAt: { type: "string" },
399
412
  // Populated only on the query route, by an `expand` node: linked objects
@@ -2,4 +2,8 @@ import { z } from "zod"
2
2
 
3
3
  export const ProjectInfoResponseSchema = z.object({
4
4
  id: z.string(),
5
+ /** Canonical BCP 47 language of the project, `"en"` unless configured. */
6
+ locale: z.string(),
7
+ /** Canonical IANA time zone of the project, `"UTC"` unless configured. */
8
+ timeZone: z.string(),
5
9
  })
package/src/server.ts CHANGED
@@ -5,7 +5,7 @@ import { CSRF_HEADER_NAME, setRequestClientAddress } from "@sixb/core/internal/a
5
5
  import { bindRequestExecution } from "@sixb/core/internal/request-execution"
6
6
  import { setApiPublicOrigin } from "@sixb/core/internal/runtime"
7
7
  import type { Server } from "bun"
8
- import { Elysia } from "elysia"
8
+ import { Elysia, ParseError } from "elysia"
9
9
  import { websocket as elysiaWebSocket } from "elysia/ws"
10
10
  import { zodToJsonSchema } from "zod-to-json-schema"
11
11
  import {
@@ -56,10 +56,15 @@ import {
56
56
  import { OPENAPI_TAG_METADATA } from "./openapi/tags"
57
57
  import { registerHttpRoutes } from "./registerRoutes"
58
58
  import { registerAuthRoutes } from "./routes/auth"
59
+ import { DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES } from "./routes/files"
59
60
  import { registerWebhookRoutes } from "./routes/webhooks"
60
61
  import { registerWebSocketRoutes } from "./routes/ws"
61
62
  import { jsonValueOpenApiOverride } from "./schemas/common"
62
63
  import { ObjectQueryOpenApiSchemas } from "./schemas/objects"
64
+ import { limitRequestBody, RequestBodyTooLargeError } from "./utils/request-body"
65
+
66
+ // Clients send only subscription messages; Bun's default would buffer up to 16 MB for one.
67
+ export const MAX_WEBSOCKET_MESSAGE_BYTES = 64 * 1024
63
68
 
64
69
  export interface SixbServerOptions {
65
70
  host: SixbHostView
@@ -263,6 +268,13 @@ export function createSixbApi(server: SixbServer) {
263
268
  }
264
269
  return shared.kind === "deny" ? shared.response : undefined
265
270
  })
271
+ // A body over its limit fails while Elysia parses it, before the auth guard or handler runs.
272
+ app.onError(({ error, set }) => {
273
+ if (error instanceof ParseError && error.cause instanceof RequestBodyTooLargeError) {
274
+ set.status = 413
275
+ return { error: error.cause.message }
276
+ }
277
+ })
266
278
 
267
279
  // Resolve authentication and bind one execution SDK at the request boundary. Protected routes
268
280
  // never choose between a principal SDK and the ambient runtime themselves.
@@ -425,13 +437,14 @@ export function createSixbApi(server: SixbServer) {
425
437
  })
426
438
  )
427
439
 
440
+ const authExperience = server.getAuthExperience()
428
441
  registerAuthRoutes(app, host, {
429
442
  resolveAuthContext: (request) => server.resolveAuthContext(request),
430
443
  resolveAuthRedirectContext: (request, input) =>
431
444
  server.resolveAuthRedirectContext(request, input),
432
445
  getInvitationDestinationOptions: (request) => server.getInvitationDestinationOptions(request),
433
446
  resolveAuthRequestOrigin: (request) => server.resolveAuthRequestOrigin(request),
434
- authExperience: server.getAuthExperience(),
447
+ authExperience: authExperience && { ...authExperience, locale: host.locale },
435
448
  resolveInvitationRedirectContext: (request, input) =>
436
449
  server.resolveInvitationRedirectContext(request, input),
437
450
  })
@@ -531,8 +544,13 @@ function startApiServer(
531
544
  const bunServer = Bun.serve({
532
545
  port: options.port,
533
546
  hostname: options.host,
534
- fetch: (request: Request, server: Server<unknown>) => {
535
- const socketAddress = server.requestIP(request)?.address
547
+ // No route reads more than a simple upload form, so Bun rejects anything larger with 413.
548
+ maxRequestBodySize: DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES,
549
+ fetch: (incoming: Request, server: Server<unknown>) => {
550
+ const socketAddress = server.requestIP(incoming)?.address
551
+ // Elysia parses a body before the auth guard runs, so cap it here, as it streams. The capped
552
+ // request replaces this one before any state is keyed to it.
553
+ const request = limitRequestBody(incoming)
536
554
  if (socketAddress) {
537
555
  const forwardedFor = request.headers.get("x-forwarded-for")
538
556
  setRequestClientAddress(request, options.resolveClientAddress(socketAddress, forwardedFor))
@@ -551,6 +569,7 @@ function getElysiaWsHandler(app: SixbApp) {
551
569
  return {
552
570
  ...elysiaWebSocket,
553
571
  ...(cfg?.websocket ?? {}),
572
+ maxPayloadLength: MAX_WEBSOCKET_MESSAGE_BYTES,
554
573
  } as Parameters<typeof Bun.serve>[0]["websocket"]
555
574
  }
556
575
 
package/src/utils/http.ts CHANGED
@@ -15,6 +15,7 @@ import { RequestBodyTooLargeError } from "./request-body"
15
15
 
16
16
  /** Explicit transport policy for coded failures that are safe to surface as non-500 responses. */
17
17
  const HTTP_STATUS_BY_ERROR_CODE: Partial<Record<SixbErrorCode, number>> = {
18
+ "action.run_in_progress": 409,
18
19
  "connector.adapter_invalid": 502,
19
20
  "connector.authorization_invalid": 400,
20
21
  "connector.authorization_required": 409,
@@ -29,6 +30,7 @@ const HTTP_STATUS_BY_ERROR_CODE: Partial<Record<SixbErrorCode, number>> = {
29
30
  "connector.revocation_pending": 409,
30
31
  "dataset.not_found": 404,
31
32
  "dataset.version_not_found": 404,
33
+ "runtime.stopping": 503,
32
34
  "ai.usage_limit_exceeded": 429,
33
35
  "ai.usage_limit_unavailable": 429,
34
36
  }
@@ -1,11 +1,16 @@
1
1
  /**
2
- * Reads a request body fully into memory while enforcing a hard byte ceiling.
2
+ * Request body limits for the API.
3
3
  *
4
- * The cap is applied DURING streaming (not after buffering), so an oversized or
5
- * chunked/unknown-length body is rejected before it is fully read — the
6
- * `content-length` header, when present, only provides an early fast-path. This
7
- * is the single bounded-reader used by request handlers that need the raw bytes.
4
+ * Elysia parses a JSON or form body before the auth guard runs, so the server caps every body it
5
+ * receives at `DEFAULT_REQUEST_BODY_LIMIT_BYTES` (`limitRequestBody`). A route that takes more,
6
+ * such as a file upload, reads its own body with `readRequestBodyWithLimit`, whose limit replaces
7
+ * that cap. Both apply the limit DURING streaming (not after buffering), so an oversized or
8
+ * chunked/unknown-length body is rejected before it is fully read.
8
9
  */
10
+
11
+ /** The most a request body may be, unless the route reading it allows more. */
12
+ export const DEFAULT_REQUEST_BODY_LIMIT_BYTES = 1024 * 1024
13
+
9
14
  export class RequestBodyTooLargeError extends Error {
10
15
  readonly name = "RequestBodyTooLargeError"
11
16
 
@@ -17,11 +22,55 @@ export class RequestBodyTooLargeError extends Error {
17
22
  }
18
23
  }
19
24
 
25
+ const requestBodyCaps = new WeakMap<Request, { lifted: boolean }>()
26
+
27
+ /**
28
+ * Returns `request` with its body capped at `DEFAULT_REQUEST_BODY_LIMIT_BYTES`. Reading past the
29
+ * cap fails with `RequestBodyTooLargeError`, which Elysia surfaces as a parse error.
30
+ */
31
+ export function limitRequestBody(request: Request): Request {
32
+ if (!request.body) {
33
+ return request
34
+ }
35
+
36
+ const cap = { lifted: false }
37
+ let total = 0
38
+ const body = request.body.pipeThrough(
39
+ new TransformStream<Uint8Array, Uint8Array>({
40
+ transform(chunk, controller) {
41
+ total += chunk.byteLength
42
+ if (!cap.lifted && total > DEFAULT_REQUEST_BODY_LIMIT_BYTES) {
43
+ controller.error(new RequestBodyTooLargeError(DEFAULT_REQUEST_BODY_LIMIT_BYTES))
44
+ return
45
+ }
46
+ controller.enqueue(chunk)
47
+ },
48
+ })
49
+ )
50
+ const limited = new Request(request, { body, duplex: "half" } as RequestInit & {
51
+ duplex: "half"
52
+ })
53
+ requestBodyCaps.set(limited, cap)
54
+ return limited
55
+ }
56
+
57
+ /**
58
+ * Reads a request body fully into memory, failing once it passes `limitBytes`. That limit
59
+ * replaces the server's default cap for this request, so a route reading more than the default
60
+ * must authenticate the caller first. The `content-length` header, when present, only provides an
61
+ * early fast-path.
62
+ */
20
63
  export async function readRequestBodyWithLimit(
21
64
  request: Request,
22
65
  limitBytes: number,
23
66
  tooLargeMessage?: string
24
- ): Promise<Uint8Array> {
67
+ ): Promise<Uint8Array<ArrayBuffer>> {
68
+ // The loop below enforces `limitBytes` in place of the server's cap.
69
+ const cap = requestBodyCaps.get(request)
70
+ if (cap) {
71
+ cap.lifted = true
72
+ }
73
+
25
74
  const contentLength = request.headers.get("content-length")
26
75
  if (contentLength !== null) {
27
76
  const declared = Number(contentLength)