@sixb/server 0.2.5 → 0.2.7

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 (106) hide show
  1. package/dist/auth/run-token.d.ts.map +1 -1
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +596 -92
  5. package/dist/index.js.map +36 -35
  6. package/dist/registerRoutes.d.ts +1 -0
  7. package/dist/registerRoutes.d.ts.map +1 -1
  8. package/dist/routes/actions.d.ts +2 -0
  9. package/dist/routes/actions.d.ts.map +1 -1
  10. package/dist/routes/agent-approvals.d.ts +23 -1
  11. package/dist/routes/agent-approvals.d.ts.map +1 -1
  12. package/dist/routes/agent-computers.d.ts +36 -0
  13. package/dist/routes/agent-computers.d.ts.map +1 -1
  14. package/dist/routes/agent-thread-reads.d.ts +82 -0
  15. package/dist/routes/agent-thread-reads.d.ts.map +1 -0
  16. package/dist/routes/agents.d.ts +795 -13
  17. package/dist/routes/agents.d.ts.map +1 -1
  18. package/dist/routes/ai-accounting.d.ts.map +1 -1
  19. package/dist/routes/connectors.d.ts +2 -0
  20. package/dist/routes/connectors.d.ts.map +1 -1
  21. package/dist/routes/datasets.d.ts +2 -0
  22. package/dist/routes/datasets.d.ts.map +1 -1
  23. package/dist/routes/model-generations.d.ts +6 -0
  24. package/dist/routes/model-generations.d.ts.map +1 -1
  25. package/dist/routes/observed-agent-threads.d.ts +24 -2
  26. package/dist/routes/observed-agent-threads.d.ts.map +1 -1
  27. package/dist/routes/ontology.d.ts +2 -0
  28. package/dist/routes/ontology.d.ts.map +1 -1
  29. package/dist/routes/pipelines.d.ts +2 -0
  30. package/dist/routes/pipelines.d.ts.map +1 -1
  31. package/dist/routes/projections.d.ts +6 -0
  32. package/dist/routes/projections.d.ts.map +1 -1
  33. package/dist/routes/rules.d.ts +2 -0
  34. package/dist/routes/rules.d.ts.map +1 -1
  35. package/dist/routes/status.d.ts +5 -2
  36. package/dist/routes/status.d.ts.map +1 -1
  37. package/dist/routes/syncs.d.ts +177 -12
  38. package/dist/routes/syncs.d.ts.map +1 -1
  39. package/dist/routes/workflows.d.ts +8 -6
  40. package/dist/routes/workflows.d.ts.map +1 -1
  41. package/dist/routes/ws/agents.d.ts.map +1 -1
  42. package/dist/schemas/actions.d.ts +6 -0
  43. package/dist/schemas/actions.d.ts.map +1 -1
  44. package/dist/schemas/activity.d.ts +4 -4
  45. package/dist/schemas/agents.d.ts +2657 -61
  46. package/dist/schemas/agents.d.ts.map +1 -1
  47. package/dist/schemas/ai-accounting.d.ts +3 -0
  48. package/dist/schemas/ai-accounting.d.ts.map +1 -1
  49. package/dist/schemas/common.d.ts +5 -0
  50. package/dist/schemas/common.d.ts.map +1 -1
  51. package/dist/schemas/connectors.d.ts +3 -0
  52. package/dist/schemas/connectors.d.ts.map +1 -1
  53. package/dist/schemas/datasets.d.ts +3 -0
  54. package/dist/schemas/datasets.d.ts.map +1 -1
  55. package/dist/schemas/models.d.ts +46 -0
  56. package/dist/schemas/models.d.ts.map +1 -1
  57. package/dist/schemas/ontology.d.ts +3 -0
  58. package/dist/schemas/ontology.d.ts.map +1 -1
  59. package/dist/schemas/pipelines.d.ts +3 -0
  60. package/dist/schemas/pipelines.d.ts.map +1 -1
  61. package/dist/schemas/projections.d.ts +33 -0
  62. package/dist/schemas/projections.d.ts.map +1 -1
  63. package/dist/schemas/rules.d.ts +3 -0
  64. package/dist/schemas/rules.d.ts.map +1 -1
  65. package/dist/schemas/status.d.ts +2 -2
  66. package/dist/schemas/syncs.d.ts +727 -25
  67. package/dist/schemas/syncs.d.ts.map +1 -1
  68. package/dist/schemas/workflows.d.ts +25 -22
  69. package/dist/schemas/workflows.d.ts.map +1 -1
  70. package/dist/server.d.ts +16 -1
  71. package/dist/server.d.ts.map +1 -1
  72. package/package.json +5 -5
  73. package/src/auth/run-token.ts +59 -9
  74. package/src/index.ts +6 -1
  75. package/src/registerRoutes.ts +4 -1
  76. package/src/routes/actions.ts +7 -3
  77. package/src/routes/agent-computers.ts +7 -6
  78. package/src/routes/agent-thread-reads.ts +67 -0
  79. package/src/routes/agents.ts +129 -16
  80. package/src/routes/ai-accounting.ts +1 -0
  81. package/src/routes/connectors.ts +1 -0
  82. package/src/routes/datasets.ts +11 -3
  83. package/src/routes/model-generations.ts +1 -1
  84. package/src/routes/observed-agent-threads.ts +3 -4
  85. package/src/routes/ontology.ts +17 -3
  86. package/src/routes/pipelines.ts +13 -3
  87. package/src/routes/projections.ts +14 -9
  88. package/src/routes/rules.ts +9 -3
  89. package/src/routes/status.ts +18 -1
  90. package/src/routes/syncs.ts +139 -8
  91. package/src/routes/workflows.ts +13 -3
  92. package/src/routes/ws/agents.ts +43 -3
  93. package/src/schemas/actions.ts +7 -1
  94. package/src/schemas/agents.ts +80 -10
  95. package/src/schemas/ai-accounting.ts +12 -0
  96. package/src/schemas/common.ts +24 -9
  97. package/src/schemas/connectors.ts +2 -1
  98. package/src/schemas/datasets.ts +2 -1
  99. package/src/schemas/models.ts +10 -0
  100. package/src/schemas/ontology.ts +2 -0
  101. package/src/schemas/pipelines.ts +2 -1
  102. package/src/schemas/projections.ts +4 -1
  103. package/src/schemas/rules.ts +2 -0
  104. package/src/schemas/syncs.ts +65 -2
  105. package/src/schemas/workflows.ts +7 -1
  106. package/src/server.ts +205 -13
@@ -1,4 +1,5 @@
1
1
  import {
2
+ type AgentMessagePart,
2
3
  AgentRequestError,
3
4
  type AgentRequestErrorCode,
4
5
  type AgentRunView,
@@ -53,7 +54,7 @@ import {
53
54
  AgentInboxListResponseSchema,
54
55
  AgentMessageFileContentParamsSchema,
55
56
  AgentMessageListResponseSchema,
56
- AgentMessageSchema,
57
+ type AgentMessageSchema,
57
58
  AgentMessagesQuerySchema,
58
59
  AgentRequestErrorResponseSchema,
59
60
  AgentRunListQuerySchema,
@@ -72,6 +73,8 @@ import {
72
73
  CancelAgentRunResponseSchema,
73
74
  CreateAgentThreadBodySchema,
74
75
  CreateAgentThreadResponseSchema,
76
+ EditAgentMessageBodySchema,
77
+ EditAgentMessageResponseSchema,
75
78
  PostAgentMessageBodySchema,
76
79
  PostAgentMessageResponseSchema,
77
80
  RetryAgentRunResponseSchema,
@@ -147,6 +150,23 @@ export async function serializeThreads(
147
150
  messageCount: thread.messageCount,
148
151
  createdAt: toIsoString(thread.createdAt),
149
152
  updatedAt: toIsoString(thread.updatedAt),
153
+ read: thread.read && {
154
+ threadId: thread.read.threadId,
155
+ throughSeq: thread.read.throughSeq,
156
+ headSeq: thread.read.headSeq,
157
+ unread: thread.read.unread,
158
+ readAt: thread.read.readAt ? toIsoString(thread.read.readAt) : undefined,
159
+ },
160
+ lastRun: thread.lastRun && {
161
+ id: thread.lastRun.id,
162
+ status: thread.lastRun.status,
163
+ finishReason: thread.lastRun.finishReason,
164
+ errorCode: thread.lastRun.errorCode,
165
+ completedAt: thread.lastRun.completedAt
166
+ ? toIsoString(thread.lastRun.completedAt)
167
+ : undefined,
168
+ requestedBy: thread.lastRun.requestedBy,
169
+ },
150
170
  })
151
171
  )
152
172
  }
@@ -228,12 +248,16 @@ export function sameBackgroundCommand(
228
248
  )
229
249
  }
230
250
 
251
+ /**
252
+ * A message as the API returns it, unchecked: the route's response schema checks it once, and drops
253
+ * what the schema does not name. Parsed here too, a thread's messages were checked three times.
254
+ */
231
255
  function serializeMessage(
232
256
  message: AgentMessageRecord,
233
257
  annotations: readonly AgentRunDiagnostic[] = [],
234
258
  checkpoint?: AgentContextCheckpointRecord
235
- ): ReturnType<typeof AgentMessageSchema.parse> {
236
- return AgentMessageSchema.parse({
259
+ ): z.infer<typeof AgentMessageSchema> {
260
+ return {
237
261
  id: message.id,
238
262
  projectId: message.projectId,
239
263
  threadId: message.threadId,
@@ -241,7 +265,7 @@ function serializeMessage(
241
265
  role: message.role,
242
266
  authorPrincipal: message.authorPrincipal,
243
267
  seq: message.seq,
244
- parts: message.parts,
268
+ parts: message.parts.map(withoutReplayState),
245
269
  annotations,
246
270
  compaction: checkpoint
247
271
  ? {
@@ -255,7 +279,20 @@ function serializeMessage(
255
279
  contentVersion: message.contentVersion,
256
280
  createdAt: toIsoString(message.createdAt),
257
281
  completedAt: message.completedAt ? toIsoString(message.completedAt) : undefined,
258
- })
282
+ } as z.infer<typeof AgentMessageSchema>
283
+ }
284
+
285
+ /**
286
+ * A part without what only replays the conversation to its model: a provider's opaque state and
287
+ * metadata, such as encrypted reasoning, which no reader shows and which made up some 40% of a long
288
+ * thread's messages. A provider-state part stays, with no data, so each part keeps its index for
289
+ * the `/parts/<index>/...` paths files are read at.
290
+ */
291
+ function withoutReplayState(part: AgentMessagePart): AgentMessagePart {
292
+ if (part.type === "provider-state") return { ...part, data: null }
293
+ if (!("providerMetadata" in part) || part.providerMetadata === undefined) return part
294
+ const { providerMetadata: _replay, ...shown } = part
295
+ return shown as AgentMessagePart
259
296
  }
260
297
 
261
298
  export function serializeAgentInboxItem(
@@ -274,12 +311,20 @@ export function serializeAgentInboxItem(
274
311
  timeZone: item.timeZone,
275
312
  locale: item.locale,
276
313
  immediate: item.immediate === true ? true : undefined,
314
+ replacesMessageId: item.replacesMessageId,
277
315
  createdAt: toIsoString(item.createdAt),
278
316
  updatedAt: toIsoString(item.updatedAt),
279
317
  })
280
318
  }
281
319
 
282
- export function serializeAgentRun(run: AgentRunView): ReturnType<typeof AgentRunSchema.parse> {
320
+ /**
321
+ * A run as the API returns it. `ownerReads`: its thread's owner reads it, and alone sees the folder
322
+ * on their computer it runs in, as with the thread's own `computer`.
323
+ */
324
+ export function serializeAgentRun(
325
+ run: AgentRunView,
326
+ { ownerReads = false }: { readonly ownerReads?: boolean } = {}
327
+ ): ReturnType<typeof AgentRunSchema.parse> {
283
328
  return AgentRunSchema.parse({
284
329
  id: run.id,
285
330
  projectId: run.projectId,
@@ -294,6 +339,7 @@ export function serializeAgentRun(run: AgentRunView): ReturnType<typeof AgentRun
294
339
  reasoning: run.spec?.reasoning,
295
340
  approvalMode: run.spec?.approvalMode,
296
341
  runsOn: run.kind === "conversation" ? run.spec?.runsOn : undefined,
342
+ computer: ownerReads && run.kind === "conversation" ? run.spec?.computer : undefined,
297
343
  modelId: run.modelId,
298
344
  finishReason: run.finishReason,
299
345
  usage: run.usage,
@@ -374,12 +420,14 @@ export function handleAgentRouteError(
374
420
  // Core performs visibility checks before workspace state transitions.
375
421
  switch (error.code) {
376
422
  case "agent_not_found":
423
+ case "message_not_found":
377
424
  case "run_not_found":
378
425
  case "thread_not_found":
379
426
  case "approval_not_found":
380
427
  set.status = 404
381
428
  break
382
429
  case "active_run_exists":
430
+ case "message_not_editable":
383
431
  case "thread_not_conversation":
384
432
  case "run_not_retryable":
385
433
  case "run_not_active":
@@ -389,6 +437,7 @@ export function handleAgentRouteError(
389
437
  set.status = 409
390
438
  break
391
439
  case "authority_not_inheritable":
440
+ case "not_message_author":
392
441
  case "not_thread_owner":
393
442
  case "not_run_requester":
394
443
  set.status = 403
@@ -958,9 +1007,8 @@ export function registerAgentRoutes(app: Elysia, host: SixbHostView) {
958
1007
  }
959
1008
 
960
1009
  const parsed = AgentMessagesQuerySchema.parse(query)
961
- return AgentMessageListResponseSchema.parse(
962
- await readThreadMessages(host, storage, thread, parsed)
963
- )
1010
+ // The response schema checks the page once, as it leaves.
1011
+ return await readThreadMessages(host, storage, thread, parsed)
964
1012
  } catch (error) {
965
1013
  return handleAgentRouteError(error, set)
966
1014
  }
@@ -1188,6 +1236,64 @@ export function registerAgentRoutes(app: Elysia, host: SixbHostView) {
1188
1236
  },
1189
1237
  }
1190
1238
  )
1239
+ .post(
1240
+ "/api/agent-threads/:threadId/messages/:messageId/edit",
1241
+ async (context) => {
1242
+ const { params, body, set } = context
1243
+ const sixb = requireRequestSixb(context)
1244
+ try {
1245
+ const storage = host.storage.agents
1246
+ if (!storage) {
1247
+ return missingAgentStorageResponse(set)
1248
+ }
1249
+
1250
+ const parsed = EditAgentMessageBodySchema.parse(body)
1251
+ const result = await sixb.agent.runs.editMessage({
1252
+ threadId: params.threadId,
1253
+ messageId: params.messageId,
1254
+ text: parsed.text,
1255
+ model: parsed.model,
1256
+ reasoning: parsed.reasoning,
1257
+ timeZone: parsed.timeZone,
1258
+ locale: parsed.locale,
1259
+ approvalMode: parsed.approvalMode,
1260
+ attachments: parsed.attachments as readonly FileRef[] | undefined,
1261
+ context: parsed.context,
1262
+ nextMessageId: parsed.nextMessageId,
1263
+ })
1264
+
1265
+ set.status = 202
1266
+ return EditAgentMessageResponseSchema.parse(
1267
+ result.kind === "turn"
1268
+ ? { run: serializeAgentRun(result.run) }
1269
+ : { item: serializeAgentInboxItem(result.item) }
1270
+ )
1271
+ } catch (error) {
1272
+ return handleAgentInboxRouteError(error, set)
1273
+ }
1274
+ },
1275
+ {
1276
+ params: AgentMessageFileContentParamsSchema,
1277
+ body: EditAgentMessageBodySchema,
1278
+ response: {
1279
+ 202: EditAgentMessageResponseSchema,
1280
+ 400: AgentRequestErrorResponseSchema,
1281
+ 403: AgentRequestErrorResponseSchema,
1282
+ 404: ErrorResponseSchema,
1283
+ 409: AgentRequestErrorResponseSchema,
1284
+ 429: AiUsageLimitErrorResponseSchema,
1285
+ 501: ErrorResponseSchema,
1286
+ },
1287
+ detail: {
1288
+ summary: "Edit an agent thread message and restart from that turn",
1289
+ description:
1290
+ "Replaces a user-authored message in place, removes any messages and compaction summaries from that turn onward, and starts a new turn from the edited message. While a turn runs, the edit stops it and waits in the thread's inbox: the turn's end rewinds the thread and starts the edited message.",
1291
+ tags: [OPENAPI_TAGS.agentThreads.name],
1292
+ operationId: "editAgentThreadMessage",
1293
+ security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT,
1294
+ },
1295
+ }
1296
+ )
1191
1297
  .post(
1192
1298
  "/api/agent-threads/:threadId/cancel",
1193
1299
  async (context) => {
@@ -1403,19 +1509,26 @@ export function registerAgentRoutes(app: Elysia, host: SixbHostView) {
1403
1509
  }
1404
1510
 
1405
1511
  const parsed = AgentRunListQuerySchema.parse(query)
1406
- const result = await sixb.agent.runs.listForThread(params.threadId, {
1407
- statuses: parsed.status ? [parsed.status] : undefined,
1408
- limit: parseOptionalInt(parsed.limit),
1409
- offset: parseOptionalInt(parsed.offset),
1410
- order: parsed.order,
1411
- })
1512
+ const [result, thread] = await Promise.all([
1513
+ sixb.agent.runs.listForThread(params.threadId, {
1514
+ statuses: parsed.status ? [parsed.status] : undefined,
1515
+ limit: parseOptionalInt(parsed.limit),
1516
+ offset: parseOptionalInt(parsed.offset),
1517
+ order: parsed.order,
1518
+ }),
1519
+ storage.threads.getById({ projectId: host.id, id: params.threadId }),
1520
+ ])
1412
1521
  if (!result) {
1413
1522
  set.status = 404
1414
1523
  return { error: "Agent thread not found" }
1415
1524
  }
1416
1525
 
1526
+ // Its owner reads where each turn ran, down to the folder: the app marks every move.
1527
+ const ownerReads =
1528
+ thread !== null && principalsEqual(thread.ownerPrincipal, requestActor(sixb))
1529
+
1417
1530
  return AgentRunListResponseSchema.parse({
1418
- runs: result.runs.map(serializeAgentRun),
1531
+ runs: result.runs.map((run) => serializeAgentRun(run, { ownerReads })),
1419
1532
  hasMore: result.hasMore,
1420
1533
  total: result.total,
1421
1534
  })
@@ -348,6 +348,7 @@ export function registerAiAccountingRoutes(app: Elysia, host: SixbHostView) {
348
348
  from: new Date(parsed.from),
349
349
  to: new Date(parsed.to),
350
350
  bucket: parsed.bucket,
351
+ ...(parsed.timeZone === undefined ? {} : { timeZone: parsed.timeZone }),
351
352
  providerId: parsed.providerId,
352
353
  modelId: parsed.modelId,
353
354
  ...accountingFilters(parsed),
@@ -14,6 +14,7 @@ function serializeConnector(
14
14
  ) {
15
15
  return {
16
16
  id: connector.id,
17
+ folder: host.definitions.folders.connectors?.get(connector.id),
17
18
  type: connector.adapter.type,
18
19
  connection: isOAuthConnectorDefinition(connector)
19
20
  ? { authentication: "oauth2" as const }
@@ -149,10 +149,12 @@ function serializeLatestVersionSummary(summary: DatasetLatestVersionSummary) {
149
149
  function serializeDatasetCatalogItem(
150
150
  dataset: DatasetDefinition,
151
151
  state: DatasetCatalogState | undefined,
152
- references: DatasetReferences
152
+ references: DatasetReferences,
153
+ folder: string | undefined
153
154
  ) {
154
155
  return DatasetCatalogItemSchema.parse({
155
156
  ...dataset,
157
+ folder,
156
158
  materialized: state?.materialized ?? false,
157
159
  latestVersion: state?.latestVersion ? serializeLatestVersionSummary(state.latestVersion) : null,
158
160
  syncIds: references.syncIds,
@@ -175,7 +177,8 @@ async function serializeDatasetCatalogItems(
175
177
  serializeDatasetCatalogItem(
176
178
  definition,
177
179
  stateByDatasetId.get(definition.id),
178
- references.get(definition.id) ?? EMPTY_DATASET_REFERENCES
180
+ references.get(definition.id) ?? EMPTY_DATASET_REFERENCES,
181
+ host.definitions.folders.datasets?.get(definition.id)
179
182
  )
180
183
  )
181
184
  }
@@ -238,7 +241,12 @@ export function registerDatasetRoutes(app: Elysia, host: SixbHostView) {
238
241
  const dataset = requireDataset(sixb, params.datasetId)
239
242
  const [state] = await host.lakeStorage.listDatasetCatalogState([dataset.id])
240
243
  const references = buildDatasetReferenceIndex(sixb).get(dataset.id)
241
- return serializeDatasetCatalogItem(dataset, state, references ?? EMPTY_DATASET_REFERENCES)
244
+ return serializeDatasetCatalogItem(
245
+ dataset,
246
+ state,
247
+ references ?? EMPTY_DATASET_REFERENCES,
248
+ host.definitions.folders.datasets?.get(dataset.id)
249
+ )
242
250
  } catch (error) {
243
251
  return handleRouteError(error, set)
244
252
  }
@@ -275,7 +275,7 @@ export function registerModelGenerationRoutes(app: Elysia, host: SixbHostView) {
275
275
  model: entry.model,
276
276
  signal: request.signal,
277
277
  })
278
- return TranscriptionSchema.parse({ ...result(entry, call), text: call.output.text })
278
+ return TranscriptionSchema.parse({ ...result(entry, call), ...call.output })
279
279
  } catch (error) {
280
280
  return generationError(error, set)
281
281
  }
@@ -89,9 +89,8 @@ export function registerObservedAgentThreadRoutes(app: Elysia, host: SixbHostVie
89
89
  }
90
90
 
91
91
  const query = AgentMessagesQuerySchema.parse(context.query)
92
- return AgentMessageListResponseSchema.parse(
93
- await readThreadMessages(host, storage, thread, query)
94
- )
92
+ // The response schema checks the page once, as it leaves.
93
+ return await readThreadMessages(host, storage, thread, query)
95
94
  } catch (error) {
96
95
  return handleAgentRouteError(error, context.set)
97
96
  }
@@ -159,7 +158,7 @@ export function registerObservedAgentThreadRoutes(app: Elysia, host: SixbHostVie
159
158
  }
160
159
 
161
160
  return AgentRunListResponseSchema.parse({
162
- runs: result.runs.map(serializeAgentRun),
161
+ runs: result.runs.map((run) => serializeAgentRun(run)),
163
162
  hasMore: result.hasMore,
164
163
  total: result.total,
165
164
  })
@@ -70,10 +70,12 @@ function serializeSearch(
70
70
  function serializeObjectType(
71
71
  execution: Sixb,
72
72
  valueTypesById: ReadonlyMap<string, ValueType>,
73
- objectType: ReturnType<SixbHostView["definitions"]["ontology"]["listObjectTypes"]>[number]
73
+ objectType: ReturnType<SixbHostView["definitions"]["ontology"]["listObjectTypes"]>[number],
74
+ folder: string | undefined
74
75
  ) {
75
76
  return {
76
77
  id: objectType.id,
78
+ folder,
77
79
  name: objectType.name,
78
80
  description: objectType.description,
79
81
  extends: objectType.extends,
@@ -118,7 +120,14 @@ export function registerOntologyRoutes(app: Elysia, host: SixbHostView) {
118
120
  const valueTypesById = host.definitions.ontology.getValueTypesById()
119
121
  return sixb.objects
120
122
  .listTypes()
121
- .map((objectType) => serializeObjectType(sixb, valueTypesById, objectType))
123
+ .map((objectType) =>
124
+ serializeObjectType(
125
+ sixb,
126
+ valueTypesById,
127
+ objectType,
128
+ host.definitions.folders.objectTypes?.get(objectType.id)
129
+ )
130
+ )
122
131
  },
123
132
  {
124
133
  response: { 200: ObjectTypeSchema.array() },
@@ -141,7 +150,12 @@ export function registerOntologyRoutes(app: Elysia, host: SixbHostView) {
141
150
  return { error: "Object type not found" }
142
151
  }
143
152
 
144
- return serializeObjectType(sixb, host.definitions.ontology.getValueTypesById(), objectType)
153
+ return serializeObjectType(
154
+ sixb,
155
+ host.definitions.ontology.getValueTypesById(),
156
+ objectType,
157
+ host.definitions.folders.objectTypes?.get(objectType.id)
158
+ )
145
159
  },
146
160
  {
147
161
  params: ObjectTypeParamsSchema,
@@ -98,10 +98,12 @@ async function getLatestPipelineRuns(
98
98
 
99
99
  function serializePipeline(
100
100
  pipeline: PipelineDefinition,
101
- latestRun: SerializedPipelineRun | null
101
+ latestRun: SerializedPipelineRun | null,
102
+ folder: string | undefined
102
103
  ): ReturnType<typeof PipelineSchema.parse> {
103
104
  return PipelineSchema.parse({
104
105
  id: pipeline.id,
106
+ folder,
105
107
  triggers: pipeline.triggers,
106
108
  graph: {
107
109
  kind: pipeline.graph.kind,
@@ -136,7 +138,11 @@ export function registerPipelineRoutes(app: Elysia, host: SixbHostView) {
136
138
  )
137
139
 
138
140
  return pipelines.map((pipeline) =>
139
- serializePipeline(pipeline, latestRuns.get(pipeline.id) ?? null)
141
+ serializePipeline(
142
+ pipeline,
143
+ latestRuns.get(pipeline.id) ?? null,
144
+ host.definitions.folders.pipelines?.get(pipeline.id)
145
+ )
140
146
  )
141
147
  },
142
148
  {
@@ -160,7 +166,11 @@ export function registerPipelineRoutes(app: Elysia, host: SixbHostView) {
160
166
  return { error: "Pipeline not found" }
161
167
  }
162
168
 
163
- return serializePipeline(pipeline, await getLatestPipelineRun(sixb, pipeline.id))
169
+ return serializePipeline(
170
+ pipeline,
171
+ await getLatestPipelineRun(sixb, pipeline.id),
172
+ host.definitions.folders.pipelines?.get(pipeline.id)
173
+ )
164
174
  },
165
175
  {
166
176
  params: PipelineParamsSchema,
@@ -85,39 +85,44 @@ function projectionCatalogIds(catalog: ViewableProjectionCatalog): string[] {
85
85
  type SerializedProjection<TProjection extends ProjectionDefinition> =
86
86
  TProjection extends ObjectProjectionDefinition
87
87
  ? Omit<TProjection, "conflictResolution"> & {
88
+ folder: string | undefined
88
89
  conflictResolution: SourceEditConflictResolution
89
90
  latestRun: SerializedProjectionRun | null
90
91
  }
91
- : TProjection & { latestRun: SerializedProjectionRun | null }
92
+ : TProjection & { folder: string | undefined; latestRun: SerializedProjectionRun | null }
92
93
 
93
94
  function serializeProjection<TProjection extends ProjectionDefinition>(
94
95
  projection: TProjection,
95
- latestRuns: ReadonlyMap<string, SerializedProjectionRun>
96
+ latestRuns: ReadonlyMap<string, SerializedProjectionRun>,
97
+ folders: ReadonlyMap<string, string> | undefined
96
98
  ): SerializedProjection<TProjection> {
97
99
  const latestRun = latestRuns.get(projection.id) ?? null
100
+ const folder = folders?.get(projection.id)
98
101
  if (projection._tag === "ObjectProjectionDefinition") {
99
102
  return {
100
103
  ...projection,
104
+ folder,
101
105
  conflictResolution: projection.conflictResolution ?? { strategy: "editsWin" },
102
106
  latestRun,
103
107
  } as SerializedProjection<TProjection>
104
108
  }
105
- return { ...projection, latestRun } as SerializedProjection<TProjection>
109
+ return { ...projection, folder, latestRun } as SerializedProjection<TProjection>
106
110
  }
107
111
 
108
112
  function serializeProjectionCatalog(
109
113
  catalog: ViewableProjectionCatalog,
110
- latestRuns: ReadonlyMap<string, SerializedProjectionRun>
114
+ latestRuns: ReadonlyMap<string, SerializedProjectionRun>,
115
+ folders: ReadonlyMap<string, string> | undefined
111
116
  ) {
112
117
  return {
113
118
  objectProjections: catalog.objectProjections.map((projection) =>
114
- serializeProjection(projection, latestRuns)
119
+ serializeProjection(projection, latestRuns, folders)
115
120
  ),
116
121
  linkProjections: catalog.linkProjections.map((projection) =>
117
- serializeProjection(projection, latestRuns)
122
+ serializeProjection(projection, latestRuns, folders)
118
123
  ),
119
124
  telemetryProjections: catalog.telemetryProjections.map((projection) =>
120
- serializeProjection(projection, latestRuns)
125
+ serializeProjection(projection, latestRuns, folders)
121
126
  ),
122
127
  }
123
128
  }
@@ -130,7 +135,7 @@ export function registerProjectionRoutes(app: Elysia, host: SixbHostView) {
130
135
  const sixb = requireRequestSixb(context)
131
136
  const catalog = listViewableProjections(sixb)
132
137
  const latestRuns = await getLatestProjectionRuns(sixb, projectionCatalogIds(catalog))
133
- return serializeProjectionCatalog(catalog, latestRuns)
138
+ return serializeProjectionCatalog(catalog, latestRuns, host.definitions.folders.projections)
134
139
  },
135
140
  {
136
141
  response: { 200: ProjectionListResponseSchema },
@@ -153,7 +158,7 @@ export function registerProjectionRoutes(app: Elysia, host: SixbHostView) {
153
158
  }
154
159
 
155
160
  const latestRuns = await getLatestProjectionRuns(sixb, [found.id])
156
- return serializeProjection(found, latestRuns)
161
+ return serializeProjection(found, latestRuns, host.definitions.folders.projections)
157
162
  },
158
163
  {
159
164
  params: ProjectionParamsSchema,
@@ -14,9 +14,13 @@ import {
14
14
  } from "../schemas/rules"
15
15
  import { handleRouteError, parseOptionalInt, unconfiguredStorageResponse } from "../utils/http"
16
16
 
17
- function serializeRule(rule: RuleDefinition): ReturnType<typeof RuleSchema.parse> {
17
+ function serializeRule(
18
+ rule: RuleDefinition,
19
+ folder: string | undefined
20
+ ): ReturnType<typeof RuleSchema.parse> {
18
21
  return RuleSchema.parse({
19
22
  ...rule,
23
+ folder,
20
24
  dependencies: deriveRuleEventDependencies(rule),
21
25
  })
22
26
  }
@@ -30,7 +34,9 @@ export function registerRuleRoutes(app: Elysia, host: SixbHostView) {
30
34
  .get(
31
35
  "/api/rules",
32
36
  (context) => {
33
- return requireRequestSixb(context).rules.list().map(serializeRule)
37
+ return requireRequestSixb(context)
38
+ .rules.list()
39
+ .map((rule) => serializeRule(rule, host.definitions.folders.rules?.get(rule.id)))
34
40
  },
35
41
  {
36
42
  response: { 200: RuleSchema.array() },
@@ -51,7 +57,7 @@ export function registerRuleRoutes(app: Elysia, host: SixbHostView) {
51
57
  return { error: "Rule not found" }
52
58
  }
53
59
 
54
- return serializeRule(rule)
60
+ return serializeRule(rule, host.definitions.folders.rules?.get(rule.id))
55
61
  },
56
62
  {
57
63
  params: RuleParamsSchema,
@@ -6,7 +6,16 @@ import {
6
6
  ReadinessResponseSchema,
7
7
  StatusResponseSchema,
8
8
  } from "../schemas/status"
9
- export function registerStatusRoutes(app: Elysia, host: SixbHostView) {
9
+
10
+ export interface StatusRouteOptions {
11
+ readonly isStopping?: () => boolean
12
+ }
13
+
14
+ export function registerStatusRoutes(
15
+ app: Elysia,
16
+ host: SixbHostView,
17
+ options: StatusRouteOptions = {}
18
+ ) {
10
19
  app.get("/health", () => ({ status: "ok" as const }), {
11
20
  response: { 200: HealthResponseSchema },
12
21
  detail: {
@@ -20,6 +29,14 @@ export function registerStatusRoutes(app: Elysia, host: SixbHostView) {
20
29
  app.get(
21
30
  "/ready",
22
31
  async ({ set }) => {
32
+ if (options.isStopping?.()) {
33
+ set.status = 503
34
+ return {
35
+ status: "unready" as const,
36
+ storage: { reachable: false, schemaValid: false },
37
+ reason: "Server is shutting down.",
38
+ }
39
+ }
23
40
  const readiness = await host.checkReadiness()
24
41
  if (readiness.status === "unready") set.status = 503
25
42
  return readiness