@sixb/server 0.1.1 → 0.1.2

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 (166) hide show
  1. package/README.md +3 -3
  2. package/dist/auth/application-access.d.ts +2 -2
  3. package/dist/auth/application-access.d.ts.map +1 -1
  4. package/dist/auth/connector-callback-cookie.d.ts +12 -0
  5. package/dist/auth/connector-callback-cookie.d.ts.map +1 -0
  6. package/dist/auth/guard.d.ts +3 -3
  7. package/dist/auth/guard.d.ts.map +1 -1
  8. package/dist/auth/public-routes.d.ts.map +1 -1
  9. package/dist/auth/scope.d.ts +13 -27
  10. package/dist/auth/scope.d.ts.map +1 -1
  11. package/dist/auth/session-cookies.d.ts +2 -2
  12. package/dist/auth/session-cookies.d.ts.map +1 -1
  13. package/dist/connectors/http.d.ts +16 -0
  14. package/dist/connectors/http.d.ts.map +1 -0
  15. package/dist/index.js +3293 -2704
  16. package/dist/index.js.map +55 -50
  17. package/dist/openapi/tags.d.ts +11 -3
  18. package/dist/openapi/tags.d.ts.map +1 -1
  19. package/dist/registerRoutes.d.ts +6 -2
  20. package/dist/registerRoutes.d.ts.map +1 -1
  21. package/dist/routes/action-runs.d.ts +21 -31
  22. package/dist/routes/action-runs.d.ts.map +1 -1
  23. package/dist/routes/actions.d.ts +9 -8
  24. package/dist/routes/actions.d.ts.map +1 -1
  25. package/dist/routes/agent-api-gateway.d.ts +2 -2
  26. package/dist/routes/agent-api-gateway.d.ts.map +1 -1
  27. package/dist/routes/agents.d.ts +130 -131
  28. package/dist/routes/agents.d.ts.map +1 -1
  29. package/dist/routes/auth.d.ts +84 -84
  30. package/dist/routes/auth.d.ts.map +1 -1
  31. package/dist/routes/connector-connection-runs.d.ts +794 -0
  32. package/dist/routes/connector-connection-runs.d.ts.map +1 -0
  33. package/dist/routes/connector-connections.d.ts +219 -0
  34. package/dist/routes/connector-connections.d.ts.map +1 -0
  35. package/dist/routes/connectors.d.ts +10 -4
  36. package/dist/routes/connectors.d.ts.map +1 -1
  37. package/dist/routes/datasets.d.ts +8 -4
  38. package/dist/routes/datasets.d.ts.map +1 -1
  39. package/dist/routes/events.d.ts +8 -8
  40. package/dist/routes/events.d.ts.map +1 -1
  41. package/dist/routes/files.d.ts +11 -10
  42. package/dist/routes/files.d.ts.map +1 -1
  43. package/dist/routes/links.d.ts +2 -2
  44. package/dist/routes/links.d.ts.map +1 -1
  45. package/dist/routes/logs.d.ts +5 -5
  46. package/dist/routes/logs.d.ts.map +1 -1
  47. package/dist/routes/objects.d.ts +34 -34
  48. package/dist/routes/objects.d.ts.map +1 -1
  49. package/dist/routes/ontology.d.ts +50 -50
  50. package/dist/routes/ontology.d.ts.map +1 -1
  51. package/dist/routes/pipelines.d.ts +24 -34
  52. package/dist/routes/pipelines.d.ts.map +1 -1
  53. package/dist/routes/project.d.ts +2 -2
  54. package/dist/routes/project.d.ts.map +1 -1
  55. package/dist/routes/projections.d.ts +131 -83
  56. package/dist/routes/projections.d.ts.map +1 -1
  57. package/dist/routes/rules.d.ts +6 -6
  58. package/dist/routes/rules.d.ts.map +1 -1
  59. package/dist/routes/status.d.ts +2 -2
  60. package/dist/routes/status.d.ts.map +1 -1
  61. package/dist/routes/syncs.d.ts +20 -25
  62. package/dist/routes/syncs.d.ts.map +1 -1
  63. package/dist/routes/telemetry.d.ts +2 -2
  64. package/dist/routes/telemetry.d.ts.map +1 -1
  65. package/dist/routes/webhook-runs.d.ts +9 -9
  66. package/dist/routes/webhook-runs.d.ts.map +1 -1
  67. package/dist/routes/webhooks.d.ts +2 -2
  68. package/dist/routes/webhooks.d.ts.map +1 -1
  69. package/dist/routes/workflows.d.ts +74 -48
  70. package/dist/routes/workflows.d.ts.map +1 -1
  71. package/dist/routes/ws/agents.d.ts +11 -5
  72. package/dist/routes/ws/agents.d.ts.map +1 -1
  73. package/dist/routes/ws/events.d.ts +8 -8
  74. package/dist/routes/ws/events.d.ts.map +1 -1
  75. package/dist/routes/ws/log-subscription-hub.d.ts +6 -3
  76. package/dist/routes/ws/log-subscription-hub.d.ts.map +1 -1
  77. package/dist/routes/ws/logs.d.ts +10 -10
  78. package/dist/routes/ws/logs.d.ts.map +1 -1
  79. package/dist/schemas/actions.d.ts +97 -202
  80. package/dist/schemas/actions.d.ts.map +1 -1
  81. package/dist/schemas/agents.d.ts +442 -439
  82. package/dist/schemas/agents.d.ts.map +1 -1
  83. package/dist/schemas/ai-usage.d.ts +34 -0
  84. package/dist/schemas/ai-usage.d.ts.map +1 -0
  85. package/dist/schemas/auth.d.ts +142 -142
  86. package/dist/schemas/common.d.ts +37 -0
  87. package/dist/schemas/common.d.ts.map +1 -1
  88. package/dist/schemas/connectors.d.ts +713 -2
  89. package/dist/schemas/connectors.d.ts.map +1 -1
  90. package/dist/schemas/datasets.d.ts +2 -2
  91. package/dist/schemas/event-payloads.d.ts +6 -6
  92. package/dist/schemas/events.d.ts +34 -34
  93. package/dist/schemas/logs.d.ts +22 -22
  94. package/dist/schemas/objects.d.ts +10 -10
  95. package/dist/schemas/ontology.d.ts +118 -118
  96. package/dist/schemas/pipelines.d.ts +95 -190
  97. package/dist/schemas/pipelines.d.ts.map +1 -1
  98. package/dist/schemas/projections.d.ts +918 -563
  99. package/dist/schemas/projections.d.ts.map +1 -1
  100. package/dist/schemas/rules.d.ts +6 -6
  101. package/dist/schemas/status.d.ts +2 -2
  102. package/dist/schemas/syncs.d.ts +65 -108
  103. package/dist/schemas/syncs.d.ts.map +1 -1
  104. package/dist/schemas/webhook-runs.d.ts +41 -41
  105. package/dist/schemas/webhook-runs.d.ts.map +1 -1
  106. package/dist/schemas/workflows.d.ts +516 -183
  107. package/dist/schemas/workflows.d.ts.map +1 -1
  108. package/dist/server.d.ts +6 -6
  109. package/dist/server.d.ts.map +1 -1
  110. package/dist/utils/http.d.ts +2 -0
  111. package/dist/utils/http.d.ts.map +1 -1
  112. package/dist/utils/ws.d.ts +4 -3
  113. package/dist/utils/ws.d.ts.map +1 -1
  114. package/package.json +4 -4
  115. package/src/auth/access-token-boundary.ts +4 -4
  116. package/src/auth/application-access.ts +8 -9
  117. package/src/auth/connector-callback-cookie.ts +95 -0
  118. package/src/auth/guard.ts +11 -11
  119. package/src/auth/public-routes.ts +13 -0
  120. package/src/auth/scope.ts +26 -36
  121. package/src/auth/session-cookies.ts +3 -3
  122. package/src/connectors/http.ts +110 -0
  123. package/src/openapi/tags.ts +9 -1
  124. package/src/registerRoutes.ts +34 -23
  125. package/src/routes/action-runs.ts +39 -39
  126. package/src/routes/actions.ts +7 -13
  127. package/src/routes/agent-api-gateway.ts +41 -38
  128. package/src/routes/agents.ts +89 -200
  129. package/src/routes/auth.ts +87 -91
  130. package/src/routes/connector-connection-runs.ts +346 -0
  131. package/src/routes/connector-connections.ts +135 -0
  132. package/src/routes/connectors.ts +24 -12
  133. package/src/routes/datasets.ts +55 -54
  134. package/src/routes/events.ts +5 -5
  135. package/src/routes/files.ts +22 -30
  136. package/src/routes/links.ts +31 -35
  137. package/src/routes/logs.ts +6 -11
  138. package/src/routes/objects.ts +51 -114
  139. package/src/routes/ontology.ts +27 -38
  140. package/src/routes/pipelines.ts +28 -62
  141. package/src/routes/project.ts +3 -3
  142. package/src/routes/projections.ts +26 -38
  143. package/src/routes/rules.ts +11 -25
  144. package/src/routes/status.ts +5 -5
  145. package/src/routes/syncs.ts +19 -45
  146. package/src/routes/telemetry.ts +18 -29
  147. package/src/routes/webhook-runs.ts +5 -5
  148. package/src/routes/webhooks.ts +259 -341
  149. package/src/routes/workflows.ts +226 -248
  150. package/src/routes/ws/agents.ts +196 -66
  151. package/src/routes/ws/events.ts +11 -10
  152. package/src/routes/ws/log-subscription-hub.ts +6 -12
  153. package/src/routes/ws/logs.ts +13 -5
  154. package/src/schemas/actions.ts +58 -25
  155. package/src/schemas/agents.ts +19 -14
  156. package/src/schemas/ai-usage.ts +16 -0
  157. package/src/schemas/common.ts +24 -0
  158. package/src/schemas/connectors.ts +164 -0
  159. package/src/schemas/pipelines.ts +23 -15
  160. package/src/schemas/projections.ts +17 -3
  161. package/src/schemas/syncs.ts +13 -8
  162. package/src/schemas/webhook-runs.ts +10 -5
  163. package/src/schemas/workflows.ts +16 -6
  164. package/src/server.ts +65 -26
  165. package/src/utils/http.ts +34 -6
  166. package/src/utils/ws.ts +10 -5
@@ -1,20 +1,12 @@
1
1
  import {
2
2
  AuthorizationError,
3
- isAllowed,
4
3
  type ObjectQuery,
5
4
  ObjectQueryExecutionError,
6
5
  ObjectQueryPlanningError,
7
6
  ObjectQueryValidationError,
8
7
  type ObjectRef,
9
- type OntologySource,
10
- type Sixb,
8
+ type SixbHostView,
11
9
  } from "@sixb/core"
12
- import {
13
- countObjects,
14
- executeObjectQuery,
15
- existsObjects,
16
- facetObjects,
17
- } from "@sixb/core/internal/query"
18
10
  import type {
19
11
  ExpandedLinkValue,
20
12
  ExpandedObjectRow,
@@ -24,7 +16,7 @@ import type {
24
16
  import type { Elysia } from "elysia"
25
17
  import { ZodError, z } from "zod"
26
18
  import { bearerSecurityRequirement } from "../auth/access-token-boundary"
27
- import { type RequestAuthState, requestAuthState } from "../auth/scope"
19
+ import { requireRequestSixb } from "../auth/scope"
28
20
  import {
29
21
  createContextualFileContentResponse,
30
22
  fileContentGetResponses,
@@ -106,7 +98,13 @@ function serializeLinkValue(value: ExpandedLinkValue): SerializedLinkValue {
106
98
  return serializeExpandedObject(value as ExpandedObjectRow)
107
99
  }
108
100
 
109
- function serializePlan(plan: Awaited<ReturnType<typeof executeObjectQuery>>["plan"]) {
101
+ function serializePlan(plan: {
102
+ readonly mode: string
103
+ readonly providerIssues: readonly unknown[]
104
+ readonly fallbackIssues: readonly unknown[]
105
+ readonly issues: readonly unknown[]
106
+ readonly fallback?: { readonly maxRows: number; readonly requiresExplicitBound: boolean }
107
+ }) {
110
108
  return {
111
109
  mode: plan.mode,
112
110
  providerIssues: plan.providerIssues,
@@ -171,19 +169,10 @@ function formatZodIssuePath(path: readonly (string | number)[]): string {
171
169
  }
172
170
 
173
171
  async function getObjectRow(
174
- sixb: Sixb<readonly OntologySource[]>,
175
- scoped: ReturnType<typeof requestAuthState>["scoped"],
172
+ sixb: ReturnType<typeof requireRequestSixb>,
176
173
  params: { objectTypeId: string; objectId: string }
177
174
  ) {
178
- if (scoped) {
179
- return scoped.getObject(params.objectTypeId, params.objectId)
180
- }
181
-
182
- return sixb.storage.objects.getByPrimaryId({
183
- projectId: sixb.id,
184
- objectTypeId: params.objectTypeId,
185
- primaryId: params.objectId,
186
- })
175
+ return sixb.objects.get(params.objectTypeId, params.objectId)
187
176
  }
188
177
 
189
178
  interface ObjectSearchItem {
@@ -192,34 +181,27 @@ interface ObjectSearchItem {
192
181
  }
193
182
 
194
183
  async function searchObjects(
195
- sixb: Sixb<readonly OntologySource[]>,
196
- authState: RequestAuthState,
184
+ host: SixbHostView,
185
+ sixb: ReturnType<typeof requireRequestSixb>,
197
186
  query: string,
198
187
  limit: number
199
188
  ): Promise<readonly ObjectSearchItem[]> {
200
189
  // Primary ids are available on every object store and form the reliable fallback. Scoped.list()
201
190
  // narrows broad searches to viewable types before storage, rather than filtering rows afterwards.
202
- const primaryMatches = await (authState.scoped
203
- ? authState.scoped.list({ idPrefix: query, limit })
204
- : sixb.list({ idPrefix: query, limit }))
191
+ const primaryMatches = await sixb.objects.list({ idPrefix: query, limit })
205
192
 
206
- const capabilities = sixb.storage.objects.queryCapabilities()
193
+ const capabilities = host.storage.objects.queryCapabilities()
207
194
  const supportsTextSearch =
208
195
  capabilities.queryObjects === true &&
209
196
  capabilities.nodes?.start === true &&
210
197
  capabilities.nodes?.text === true &&
211
198
  capabilities.nodes?.limit === true &&
212
- typeof sixb.storage.objects.queryObjects === "function"
199
+ typeof host.storage.objects.queryObjects === "function"
213
200
 
214
201
  const searchableTypes = supportsTextSearch
215
- ? sixb.listObjectTypes().filter(
216
- (objectType) =>
217
- Boolean(objectType.search?.defaultText?.length) &&
218
- isAllowed(authState.authz, {
219
- kind: "object.view",
220
- objectTypeId: objectType.id,
221
- })
222
- )
202
+ ? sixb.objects
203
+ .listTypes()
204
+ .filter((objectType) => Boolean(objectType.search?.defaultText?.length))
223
205
  : []
224
206
 
225
207
  const textMatches = await Promise.all(
@@ -233,14 +215,7 @@ async function searchObjects(
233
215
  input: { kind: "start", objectTypeId: objectType.id },
234
216
  },
235
217
  }
236
- const result = await executeObjectQuery(
237
- { projectId: sixb.id, query: objectQuery },
238
- {
239
- ontology: sixb.ontology,
240
- storage: sixb.storage.objects,
241
- authorization: authState.authz ?? undefined,
242
- }
243
- )
218
+ const result = await sixb.objects.executeQuery({ query: objectQuery })
244
219
  return result.objects
245
220
  })
246
221
  )
@@ -256,8 +231,8 @@ async function searchObjects(
256
231
  return [...items.values()]
257
232
  }
258
233
 
259
- function objectSearchLabel(sixb: Sixb<readonly OntologySource[]>, row: ObjectRow): string {
260
- const objectType = sixb.resolveObjectType(row.objectTypeId)
234
+ function objectSearchLabel(sixb: ReturnType<typeof requireRequestSixb>, row: ObjectRow): string {
235
+ const objectType = sixb.objects.resolveType(row.objectTypeId)
261
236
  const titlePropertyId = objectType.search?.title
262
237
  const title = titlePropertyId ? row.properties[titlePropertyId] : undefined
263
238
  const displayTitle =
@@ -272,7 +247,7 @@ function objectRefIdentity(ref: ObjectRef): string {
272
247
  }
273
248
 
274
249
  async function objectFileContentResponse(
275
- sixb: Sixb<readonly OntologySource[]>,
250
+ host: SixbHostView,
276
251
  context: {
277
252
  readonly params: { readonly objectTypeId: string; readonly objectId: string }
278
253
  readonly query: unknown
@@ -281,10 +256,10 @@ async function objectFileContentResponse(
281
256
  },
282
257
  options: { readonly head?: boolean } = {}
283
258
  ) {
284
- const { scoped } = requestAuthState(context)
259
+ const sixb = requireRequestSixb(context)
285
260
 
286
261
  return createContextualFileContentResponse({
287
- blobStorage: sixb.blobStorage,
262
+ blobStorage: host.blobStorage,
288
263
  query: context.query,
289
264
  querySchema: ObjectFileContentQuerySchema,
290
265
  request: context.request,
@@ -292,7 +267,7 @@ async function objectFileContentResponse(
292
267
  head: options.head,
293
268
  hideError: (error) => error instanceof AuthorizationError,
294
269
  resolveRoot: async () => {
295
- const row = await getObjectRow(sixb, scoped, context.params)
270
+ const row = await getObjectRow(sixb, context.params)
296
271
  if (!row) {
297
272
  return null
298
273
  }
@@ -302,7 +277,7 @@ async function objectFileContentResponse(
302
277
  })
303
278
  }
304
279
 
305
- export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySource[]>) {
280
+ export function registerObjectRoutes(app: Elysia, host: SixbHostView) {
306
281
  return app
307
282
  .get(
308
283
  "/api/objects/search",
@@ -315,7 +290,7 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
315
290
  set.status = 400
316
291
  return { error: "Object search limit must be positive" }
317
292
  }
318
- const items = await searchObjects(sixb, requestAuthState(context), parsed.q, limit)
293
+ const items = await searchObjects(host, requireRequestSixb(context), parsed.q, limit)
319
294
  return ObjectSearchResponseSchema.parse({ items })
320
295
  } catch (error) {
321
296
  return handleObjectQueryError(error, set)
@@ -340,7 +315,7 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
340
315
  "/api/objects",
341
316
  async (context) => {
342
317
  const { query, set } = context
343
- const { scoped } = requestAuthState(context)
318
+ const sixb = requireRequestSixb(context)
344
319
 
345
320
  try {
346
321
  const params = {
@@ -356,7 +331,7 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
356
331
  orderBy: query.orderBy,
357
332
  order: query.order,
358
333
  }
359
- const result = scoped ? await scoped.list(params) : await sixb.list(params)
334
+ const result = await sixb.objects.list(params)
360
335
 
361
336
  return {
362
337
  objects: result.objects.map(serializeObject),
@@ -403,18 +378,10 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
403
378
  query: ObjectQuery
404
379
  includeTotal?: boolean
405
380
  }
406
- const result = await executeObjectQuery(
407
- {
408
- projectId: sixb.id,
409
- query: parsed.query,
410
- includeTotal: parsed.includeTotal,
411
- },
412
- {
413
- ontology: sixb.ontology,
414
- storage: sixb.storage.objects,
415
- authorization: requestAuthState(context).authz ?? undefined,
416
- }
417
- )
381
+ const result = await requireRequestSixb(context).objects.executeQuery({
382
+ query: parsed.query,
383
+ includeTotal: parsed.includeTotal,
384
+ })
418
385
 
419
386
  return {
420
387
  objects: result.objects.map(serializeExpandedObject),
@@ -486,17 +453,7 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
486
453
  const parsed = ObjectQueryCountRequestSchema.parse(body) as {
487
454
  query: ObjectQuery
488
455
  }
489
- const result = await countObjects(
490
- {
491
- projectId: sixb.id,
492
- query: parsed.query,
493
- },
494
- {
495
- ontology: sixb.ontology,
496
- storage: sixb.storage.objects,
497
- authorization: requestAuthState(context).authz ?? undefined,
498
- }
499
- )
456
+ const result = await requireRequestSixb(context).objects.count({ query: parsed.query })
500
457
 
501
458
  return {
502
459
  count: result.count,
@@ -565,17 +522,7 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
565
522
  const parsed = ObjectQueryExistsRequestSchema.parse(body) as {
566
523
  query: ObjectQuery
567
524
  }
568
- const result = await existsObjects(
569
- {
570
- projectId: sixb.id,
571
- query: parsed.query,
572
- },
573
- {
574
- ontology: sixb.ontology,
575
- storage: sixb.storage.objects,
576
- authorization: requestAuthState(context).authz ?? undefined,
577
- }
578
- )
525
+ const result = await requireRequestSixb(context).objects.exists({ query: parsed.query })
579
526
 
580
527
  return {
581
528
  exists: result.exists,
@@ -645,18 +592,10 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
645
592
  query: ObjectQuery
646
593
  facets: { propertyId: string; limit: number }[]
647
594
  }
648
- const result = await facetObjects(
649
- {
650
- projectId: sixb.id,
651
- query: parsed.query,
652
- facets: parsed.facets,
653
- },
654
- {
655
- ontology: sixb.ontology,
656
- storage: sixb.storage.objects,
657
- authorization: requestAuthState(context).authz ?? undefined,
658
- }
659
- )
595
+ const result = await requireRequestSixb(context).objects.facet({
596
+ query: parsed.query,
597
+ facets: parsed.facets,
598
+ })
660
599
 
661
600
  return {
662
601
  facets: result.facets,
@@ -719,7 +658,7 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
719
658
  )
720
659
  .get(
721
660
  "/api/objects/:objectTypeId/:objectId/files/content",
722
- (context) => objectFileContentResponse(sixb, context),
661
+ (context) => objectFileContentResponse(host, context),
723
662
  {
724
663
  params: ObjectParamsSchema,
725
664
  // Register the loose query so framework validation only requires `path`;
@@ -742,7 +681,7 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
742
681
  )
743
682
  .head(
744
683
  "/api/objects/:objectTypeId/:objectId/files/content",
745
- (context) => objectFileContentResponse(sixb, context, { head: true }),
684
+ (context) => objectFileContentResponse(host, context, { head: true }),
746
685
  {
747
686
  params: ObjectParamsSchema,
748
687
  // See the GET route: register the loose query so the handler owns the
@@ -763,10 +702,10 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
763
702
  "/api/objects/:objectTypeId/:objectId",
764
703
  async (context) => {
765
704
  const { params, set } = context
766
- const { scoped } = requestAuthState(context)
705
+ const sixb = requireRequestSixb(context)
767
706
 
768
707
  try {
769
- const row = await getObjectRow(sixb, scoped, params)
708
+ const row = await getObjectRow(sixb, params)
770
709
  if (!row) {
771
710
  set.status = 404
772
711
  return { error: "Object not found" }
@@ -798,18 +737,16 @@ export function registerObjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
798
737
  "/api/objects/:objectTypeId/:objectId",
799
738
  async (context) => {
800
739
  const { params, body, set } = context
801
- const { scoped } = requestAuthState(context)
740
+ const sixb = requireRequestSixb(context)
802
741
  try {
803
742
  const parsedBody = UpsertObjectBodySchema.parse(body)
804
- // Scoped when a principal is attached, privileged only when auth is off or the request is
805
- // public — the same fallback the read routes use. Scoped for the primary-property lookup
806
- // too: on the privileged runtime it answers 404 for an unregistered type before any grant
807
- // is checked, which told an ungranted principal apart from a registered type (403) and so
808
- // handed back the type universe that `listObjectTypes` filters out.
809
- const runtime = scoped ?? sixb
810
- const primaryPropertyId = runtime.getPrimaryPropertyId(params.objectTypeId)
743
+ // The same bound SDK performs the primary-property lookup and the write. Otherwise an
744
+ // ambient host lookup could answer 404 for an unregistered type before the principal's
745
+ // grant is checked, distinguishing it from a registered but ungranted type (403) and
746
+ // leaking the type universe that `listObjectTypes` filters out.
747
+ const primaryPropertyId = sixb.objects.getPrimaryPropertyId(params.objectTypeId)
811
748
  const properties = { ...parsedBody.properties, [primaryPropertyId]: params.objectId }
812
- const object = await runtime.upsertObject(params.objectTypeId, properties)
749
+ const object = await sixb.objects.upsert(params.objectTypeId, properties)
813
750
  return serializeObject(object)
814
751
  } catch (error) {
815
752
  // Was a local catch mapping every error to 404/400, which turned a missing grant into
@@ -1,14 +1,15 @@
1
- import { type AuthorizationContext, isAllowed, type OntologySource, type Sixb } from "@sixb/core"
1
+ import type { OntologySource, SixbHostView } from "@sixb/core"
2
+ import type { Sixb } from "@sixb/core/internal/request-execution"
2
3
  import type { Elysia } from "elysia"
3
4
  import { bearerSecurityRequirement } from "../auth/access-token-boundary"
4
- import { requestAuthState } from "../auth/scope"
5
+ import { requireRequestSixb } from "../auth/scope"
5
6
  import { OPENAPI_TAGS } from "../openapi/tags"
6
7
  import { ErrorResponseSchema } from "../schemas/common"
7
8
  import { ObjectTypeParamsSchema, ObjectTypeSchema } from "../schemas/ontology"
8
9
 
9
10
  function serializeProperty(
10
11
  property: ReturnType<
11
- Sixb<readonly OntologySource[]>["listObjectTypes"]
12
+ SixbHostView["definitions"]["ontology"]["listObjectTypes"]
12
13
  >[number]["properties"][number]
13
14
  ) {
14
15
  return {
@@ -26,7 +27,7 @@ function serializeProperty(
26
27
  }
27
28
 
28
29
  function serializeSearch(
29
- search: ReturnType<Sixb<readonly OntologySource[]>["listObjectTypes"]>[number]["search"]
30
+ search: ReturnType<SixbHostView["definitions"]["ontology"]["listObjectTypes"]>[number]["search"]
30
31
  ) {
31
32
  if (!search) return undefined
32
33
  return {
@@ -43,9 +44,8 @@ function serializeSearch(
43
44
  }
44
45
 
45
46
  function serializeObjectType(
46
- sixb: Sixb<readonly OntologySource[]>,
47
- objectType: ReturnType<Sixb<readonly OntologySource[]>["listObjectTypes"]>[number],
48
- authorization: AuthorizationContext | null
47
+ execution: Sixb<readonly OntologySource[]>,
48
+ objectType: ReturnType<SixbHostView["definitions"]["ontology"]["listObjectTypes"]>[number]
49
49
  ) {
50
50
  return {
51
51
  id: objectType.id,
@@ -65,38 +65,30 @@ function serializeObjectType(
65
65
  cardinality: link.cardinality,
66
66
  properties: link.properties?.map(serializeProperty),
67
67
  })),
68
- actions: sixb
69
- .listActionsForType(objectType)
70
- .filter((action) => isAllowed(authorization, { kind: "action.apply", actionId: action.id }))
71
- .map((action) => ({
72
- id: action.id,
73
- name: action.id,
74
- description: action.description,
75
- params: Object.entries(action.params).map(([id, config]) => ({
76
- id,
77
- name: id,
78
- schema: config.schema,
79
- required: config.required ?? false,
80
- nullable: config.nullable,
81
- description: config.description,
82
- semanticType: config.semanticType,
83
- })),
68
+ actions: execution.actions.listForType(objectType).map((action) => ({
69
+ id: action.id,
70
+ name: action.id,
71
+ description: action.description,
72
+ params: Object.entries(action.params).map(([id, config]) => ({
73
+ id,
74
+ name: id,
75
+ schema: config.schema,
76
+ required: config.required ?? false,
77
+ nullable: config.nullable,
78
+ description: config.description,
79
+ semanticType: config.semanticType,
84
80
  })),
81
+ })),
85
82
  }
86
83
  }
87
84
 
88
- export function registerOntologyRoutes(app: Elysia, sixb: Sixb<readonly OntologySource[]>) {
85
+ export function registerOntologyRoutes(app: Elysia, _host: SixbHostView) {
89
86
  return app
90
87
  .get(
91
88
  "/api/object-types",
92
89
  async (context) => {
93
- const { authz } = requestAuthState(context)
94
- return sixb
95
- .listObjectTypes()
96
- .filter((objectType) =>
97
- isAllowed(authz, { kind: "object.view", objectTypeId: objectType.id })
98
- )
99
- .map((objectType) => serializeObjectType(sixb, objectType, authz))
90
+ const sixb = requireRequestSixb(context)
91
+ return sixb.objects.listTypes().map((objectType) => serializeObjectType(sixb, objectType))
100
92
  },
101
93
  {
102
94
  response: { 200: ObjectTypeSchema.array() },
@@ -112,17 +104,14 @@ export function registerOntologyRoutes(app: Elysia, sixb: Sixb<readonly Ontology
112
104
  "/api/object-types/:objectTypeId",
113
105
  async (context) => {
114
106
  const { params, set } = context
115
- const { authz } = requestAuthState(context)
116
- const objectType = sixb.getObjectTypeById(params.objectTypeId)
117
- if (
118
- !objectType ||
119
- !isAllowed(authz, { kind: "object.view", objectTypeId: objectType.id })
120
- ) {
107
+ const sixb = requireRequestSixb(context)
108
+ const objectType = sixb.objects.getTypeById(params.objectTypeId)
109
+ if (!objectType) {
121
110
  set.status = 404
122
111
  return { error: "Object type not found" }
123
112
  }
124
113
 
125
- return serializeObjectType(sixb, objectType, authz)
114
+ return serializeObjectType(sixb, objectType)
126
115
  },
127
116
  {
128
117
  params: ObjectTypeParamsSchema,
@@ -1,8 +1,7 @@
1
- import type { OntologySource, PipelineDefinition, PipelineStepExecutor, Sixb } from "@sixb/core"
2
- import { canViewPipelineRun } from "@sixb/core/internal/authorization"
1
+ import type { PipelineDefinition, PipelineStepExecutor, SixbHostView } from "@sixb/core"
3
2
  import type { PipelineRunRecord, PipelineStepRunRecord } from "@sixb/core/storage"
4
3
  import type { Elysia } from "elysia"
5
- import { requestAuthState } from "../auth/scope"
4
+ import { requireRequestSixb } from "../auth/scope"
6
5
  import { SIXB_CSRF_SECURITY_REQUIREMENT } from "../openapi/security"
7
6
  import { OPENAPI_TAGS } from "../openapi/tags"
8
7
  import { ErrorResponseSchema } from "../schemas/common"
@@ -29,7 +28,8 @@ function serializePipelineRun(run: PipelineRunRecord) {
29
28
  projectId: run.projectId,
30
29
  pipelineId: run.pipelineId,
31
30
  status: run.status,
32
- startedAt: toIsoString(run.startedAt),
31
+ queuedAt: toIsoString(run.queuedAt),
32
+ startedAt: run.startedAt ? toIsoString(run.startedAt) : undefined,
33
33
  finishedAt: run.finishedAt ? toIsoString(run.finishedAt) : undefined,
34
34
  output: run.output,
35
35
  error: run.error,
@@ -72,36 +72,24 @@ function serializeExecutor(executor: PipelineStepExecutor) {
72
72
  }
73
73
 
74
74
  async function getLatestPipelineRun(
75
- sixb: Sixb<readonly OntologySource[]>,
75
+ sixb: ReturnType<typeof requireRequestSixb>,
76
76
  pipelineId: string
77
77
  ): Promise<SerializedPipelineRun | null> {
78
- if (!sixb.storage.pipelineRuns) {
79
- return null
80
- }
81
-
82
- const storage = sixb.storage.pipelineRuns
83
- const result = await storage.listLatestByPipelineIds({
84
- projectId: sixb.id,
85
- pipelineIds: [pipelineId],
86
- })
78
+ const result = await sixb.pipelines.runs.listLatest([pipelineId])
87
79
 
88
80
  const [latest] = result.runs
89
81
  return latest ? serializePipelineRun(latest) : null
90
82
  }
91
83
 
92
84
  async function getLatestPipelineRuns(
93
- sixb: Sixb<readonly OntologySource[]>,
85
+ sixb: ReturnType<typeof requireRequestSixb>,
94
86
  pipelineIds: readonly string[]
95
87
  ): Promise<Map<string, SerializedPipelineRun>> {
96
- const storage = sixb.storage.pipelineRuns
97
- if (!storage || pipelineIds.length === 0) {
88
+ if (pipelineIds.length === 0) {
98
89
  return new Map()
99
90
  }
100
91
 
101
- const result = await storage.listLatestByPipelineIds({
102
- projectId: sixb.id,
103
- pipelineIds,
104
- })
92
+ const result = await sixb.pipelines.runs.listLatest(pipelineIds)
105
93
 
106
94
  return new Map(result.runs.map((run) => [run.pipelineId, serializePipelineRun(run)]))
107
95
  }
@@ -133,13 +121,13 @@ function serializePipeline(
133
121
  })
134
122
  }
135
123
 
136
- export function registerPipelineRoutes(app: Elysia, sixb: Sixb<readonly OntologySource[]>) {
124
+ export function registerPipelineRoutes(app: Elysia, host: SixbHostView) {
137
125
  return app
138
126
  .get(
139
127
  "/api/pipelines",
140
128
  async (context) => {
141
- const { scoped } = requestAuthState(context)
142
- const pipelines = scoped ? scoped.listPipelines() : sixb.listPipelines()
129
+ const sixb = requireRequestSixb(context)
130
+ const pipelines = sixb.pipelines.list()
143
131
  const latestRuns = await getLatestPipelineRuns(
144
132
  sixb,
145
133
  pipelines.map((pipeline) => pipeline.id)
@@ -162,10 +150,8 @@ export function registerPipelineRoutes(app: Elysia, sixb: Sixb<readonly Ontology
162
150
  "/api/pipelines/:pipelineId",
163
151
  async (context) => {
164
152
  const { params, set } = context
165
- const { scoped } = requestAuthState(context)
166
- const pipeline = scoped
167
- ? scoped.getPipelineById(params.pipelineId)
168
- : sixb.getPipelineById(params.pipelineId)
153
+ const sixb = requireRequestSixb(context)
154
+ const pipeline = sixb.pipelines.getById(params.pipelineId)
169
155
  if (!pipeline) {
170
156
  set.status = 404
171
157
  return { error: "Pipeline not found" }
@@ -187,23 +173,16 @@ export function registerPipelineRoutes(app: Elysia, sixb: Sixb<readonly Ontology
187
173
  "/api/pipeline-runs",
188
174
  async (context) => {
189
175
  const { query, set } = context
190
- const { authz } = requestAuthState(context)
176
+ const sixb = requireRequestSixb(context)
191
177
  try {
192
178
  const parsed = PipelineRunsQuerySchema.parse(query)
193
- const storage = sixb.storage.pipelineRuns
179
+ const storage = host.storage.pipelineRuns
194
180
  if (!storage) {
195
181
  return unconfiguredStorageResponse(set, "Pipeline run storage")
196
182
  }
197
183
 
198
- // Scope to runnable pipelines the same way workflow run history does:
199
- // pass the grant allowlist alongside any explicit pipelineId and let
200
- // storage AND them. An ungranted pipelineId yields an empty
201
- // intersection, and an empty allowlist short-circuits to no rows.
202
- const pipelineIds = authz ? [...authz.grants["run:pipeline"]] : undefined
203
- const result = await storage.list({
204
- projectId: sixb.id,
184
+ const result = await sixb.pipelines.runs.list({
205
185
  pipelineId: parsed.pipelineId,
206
- pipelineIds,
207
186
  statuses: parsed.status ? [parsed.status] : undefined,
208
187
  startedAfter: parseDate(parsed.startedAfter),
209
188
  startedBefore: parseDate(parsed.startedBefore),
@@ -239,29 +218,24 @@ export function registerPipelineRoutes(app: Elysia, sixb: Sixb<readonly Ontology
239
218
  "/api/pipeline-runs/:runId",
240
219
  async (context) => {
241
220
  const { params, set } = context
242
- const { authz } = requestAuthState(context)
221
+ const sixb = requireRequestSixb(context)
243
222
  try {
244
- const storage = sixb.storage.pipelineRuns
223
+ const storage = host.storage.pipelineRuns
245
224
  if (!storage) {
246
225
  return unconfiguredStorageResponse(set, "Pipeline run storage")
247
226
  }
248
227
 
249
- const run = await storage.getById({
250
- projectId: sixb.id,
251
- id: params.runId,
252
- })
253
- // A run the principal cannot run is hidden as 404, never surfaced as a
254
- // distinct 403, mirroring the catalog and run-history routes.
255
- if (!run || !canViewPipelineRun(authz, run)) {
228
+ const run = await sixb.pipelines.runs.getById(params.runId)
229
+ if (!run) {
256
230
  set.status = 404
257
231
  return { error: "Pipeline run not found" }
258
232
  }
259
233
 
260
- const steps = await storage.listSteps({
261
- projectId: sixb.id,
262
- pipelineRunId: run.id,
263
- order: "asc",
264
- })
234
+ const steps = await sixb.pipelines.runs.listSteps(run.id, { order: "asc" })
235
+ if (!steps) {
236
+ set.status = 404
237
+ return { error: "Pipeline run not found" }
238
+ }
265
239
 
266
240
  return PipelineRunDetailResponseSchema.parse({
267
241
  run: serializePipelineRun(run),
@@ -290,17 +264,9 @@ export function registerPipelineRoutes(app: Elysia, sixb: Sixb<readonly Ontology
290
264
  "/api/pipelines/:pipelineId/runs",
291
265
  async (context) => {
292
266
  const { params, set } = context
293
- const { scoped } = requestAuthState(context)
267
+ const sixb = requireRequestSixb(context)
294
268
  try {
295
- const pipeline = sixb.getPipelineById(params.pipelineId)
296
- if (!pipeline) {
297
- set.status = 404
298
- return { error: "Pipeline not found" }
299
- }
300
-
301
- const result = scoped
302
- ? await scoped.requestPipelineRun({ pipelineId: pipeline.id })
303
- : await sixb.requestPipelineRun({ pipelineId: pipeline.id })
269
+ const result = await sixb.pipelines.request({ pipelineId: params.pipelineId })
304
270
 
305
271
  set.status = 202
306
272
  return {
@@ -1,10 +1,10 @@
1
- import type { OntologySource, Sixb } from "@sixb/core"
1
+ import type { SixbHostView } from "@sixb/core"
2
2
  import type { Elysia } from "elysia"
3
3
  import { bearerSecurityRequirement } from "../auth/access-token-boundary"
4
4
  import { OPENAPI_TAGS } from "../openapi/tags"
5
5
  import { ProjectInfoResponseSchema } from "../schemas/project"
6
- export function registerProjectRoutes(app: Elysia, sixb: Sixb<readonly OntologySource[]>) {
7
- return app.get("/api/project", async () => ({ id: sixb.id }), {
6
+ export function registerProjectRoutes(app: Elysia, host: SixbHostView) {
7
+ return app.get("/api/project", async () => ({ id: host.id }), {
8
8
  response: { 200: ProjectInfoResponseSchema },
9
9
  detail: {
10
10
  summary: "Get current project metadata",