@sixb/server 0.2.2 → 0.2.3

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 (147) hide show
  1. package/README.md +3 -3
  2. package/dist/artifacts/frame.d.ts.map +1 -1
  3. package/dist/auth/scope.d.ts +3 -0
  4. package/dist/auth/scope.d.ts.map +1 -1
  5. package/dist/auth/shared-access.d.ts +23 -0
  6. package/dist/auth/shared-access.d.ts.map +1 -1
  7. package/dist/connectors/http.d.ts +6 -1
  8. package/dist/connectors/http.d.ts.map +1 -1
  9. package/dist/index.js +2777 -683
  10. package/dist/index.js.map +41 -34
  11. package/dist/live/awareness.d.ts +48 -0
  12. package/dist/live/awareness.d.ts.map +1 -0
  13. package/dist/live/room.d.ts +198 -0
  14. package/dist/live/room.d.ts.map +1 -0
  15. package/dist/live/rooms.d.ts +67 -0
  16. package/dist/live/rooms.d.ts.map +1 -0
  17. package/dist/registerRoutes.d.ts.map +1 -1
  18. package/dist/routes/actions.d.ts +3 -3
  19. package/dist/routes/agent-approvals.d.ts +10 -10
  20. package/dist/routes/agent-children.d.ts +2 -2
  21. package/dist/routes/agent-computers.d.ts +32 -0
  22. package/dist/routes/agent-computers.d.ts.map +1 -1
  23. package/dist/routes/agent-runners.d.ts.map +1 -1
  24. package/dist/routes/agents.d.ts +48 -48
  25. package/dist/routes/artifact-frames.d.ts +2 -1
  26. package/dist/routes/artifact-frames.d.ts.map +1 -1
  27. package/dist/routes/artifacts.d.ts +1713 -178
  28. package/dist/routes/artifacts.d.ts.map +1 -1
  29. package/dist/routes/auth.d.ts +21 -21
  30. package/dist/routes/connector-connection-runs.d.ts +124 -5
  31. package/dist/routes/connector-connection-runs.d.ts.map +1 -1
  32. package/dist/routes/connector-connections.d.ts +9 -1
  33. package/dist/routes/connector-connections.d.ts.map +1 -1
  34. package/dist/routes/datasets.d.ts +5 -5
  35. package/dist/routes/events.d.ts +4 -4
  36. package/dist/routes/lake.d.ts +91 -0
  37. package/dist/routes/lake.d.ts.map +1 -0
  38. package/dist/routes/links.d.ts +6 -6
  39. package/dist/routes/logs.d.ts +2 -2
  40. package/dist/routes/model-generations.d.ts +2 -2
  41. package/dist/routes/objects.d.ts +6 -6
  42. package/dist/routes/objects.d.ts.map +1 -1
  43. package/dist/routes/observed-agent-threads.d.ts +7 -7
  44. package/dist/routes/ontology.d.ts +6 -6
  45. package/dist/routes/pipelines.d.ts +8 -4
  46. package/dist/routes/pipelines.d.ts.map +1 -1
  47. package/dist/routes/projections.d.ts +2 -2
  48. package/dist/routes/share-grants.d.ts +9 -9
  49. package/dist/routes/shared-access.d.ts +57 -2
  50. package/dist/routes/shared-access.d.ts.map +1 -1
  51. package/dist/routes/status.d.ts +11 -15
  52. package/dist/routes/status.d.ts.map +1 -1
  53. package/dist/routes/syncs.d.ts +5 -2
  54. package/dist/routes/syncs.d.ts.map +1 -1
  55. package/dist/routes/telemetry.d.ts +7 -7
  56. package/dist/routes/webhooks.d.ts.map +1 -1
  57. package/dist/routes/workflows.d.ts +3 -3
  58. package/dist/routes/ws/artifacts.d.ts +57 -0
  59. package/dist/routes/ws/artifacts.d.ts.map +1 -0
  60. package/dist/routes/ws/events.d.ts +8 -7
  61. package/dist/routes/ws/events.d.ts.map +1 -1
  62. package/dist/routes/ws/index.d.ts +2 -1
  63. package/dist/routes/ws/index.d.ts.map +1 -1
  64. package/dist/routes/ws/logs.d.ts +10 -10
  65. package/dist/routes/ws/shared-sockets.d.ts +52 -0
  66. package/dist/routes/ws/shared-sockets.d.ts.map +1 -0
  67. package/dist/schemas/actions.d.ts +7 -7
  68. package/dist/schemas/activity.d.ts +8 -8
  69. package/dist/schemas/agent-approvals.d.ts +27 -27
  70. package/dist/schemas/agents.d.ts +195 -154
  71. package/dist/schemas/agents.d.ts.map +1 -1
  72. package/dist/schemas/ai-accounting.d.ts +12 -12
  73. package/dist/schemas/artifacts.d.ts +2106 -127
  74. package/dist/schemas/artifacts.d.ts.map +1 -1
  75. package/dist/schemas/auth.d.ts +63 -63
  76. package/dist/schemas/connectors.d.ts +180 -20
  77. package/dist/schemas/connectors.d.ts.map +1 -1
  78. package/dist/schemas/datasets.d.ts +44 -44
  79. package/dist/schemas/event-payloads.d.ts +2 -2
  80. package/dist/schemas/events.d.ts +26 -26
  81. package/dist/schemas/events.d.ts.map +1 -1
  82. package/dist/schemas/files.d.ts +12 -0
  83. package/dist/schemas/files.d.ts.map +1 -1
  84. package/dist/schemas/lake.d.ts +251 -0
  85. package/dist/schemas/lake.d.ts.map +1 -0
  86. package/dist/schemas/lineage.d.ts +56 -56
  87. package/dist/schemas/logs.d.ts +18 -18
  88. package/dist/schemas/models.d.ts +4 -4
  89. package/dist/schemas/objects.d.ts.map +1 -1
  90. package/dist/schemas/ontology.d.ts +14 -14
  91. package/dist/schemas/pipelines.d.ts +70 -48
  92. package/dist/schemas/pipelines.d.ts.map +1 -1
  93. package/dist/schemas/projections.d.ts +14 -14
  94. package/dist/schemas/projections.d.ts.map +1 -1
  95. package/dist/schemas/share-grants.d.ts +30 -30
  96. package/dist/schemas/shared-access.d.ts +17 -4
  97. package/dist/schemas/shared-access.d.ts.map +1 -1
  98. package/dist/schemas/status.d.ts +59 -79
  99. package/dist/schemas/status.d.ts.map +1 -1
  100. package/dist/schemas/syncs.d.ts +26 -10
  101. package/dist/schemas/syncs.d.ts.map +1 -1
  102. package/dist/schemas/telemetry.d.ts +26 -26
  103. package/dist/schemas/workflows.d.ts +19 -19
  104. package/dist/server.d.ts +13 -0
  105. package/dist/server.d.ts.map +1 -1
  106. package/dist/utils/ws.d.ts +3 -0
  107. package/dist/utils/ws.d.ts.map +1 -1
  108. package/package.json +11 -7
  109. package/src/artifacts/frame.ts +4 -13
  110. package/src/auth/scope.ts +10 -1
  111. package/src/auth/shared-access.ts +108 -12
  112. package/src/connectors/http.ts +35 -1
  113. package/src/live/README.md +136 -0
  114. package/src/live/awareness.ts +141 -0
  115. package/src/live/room.ts +933 -0
  116. package/src/live/rooms.ts +288 -0
  117. package/src/registerRoutes.ts +2 -0
  118. package/src/routes/agent-computers.ts +59 -1
  119. package/src/routes/agent-runners.ts +1 -0
  120. package/src/routes/artifact-frames.ts +40 -12
  121. package/src/routes/artifacts.ts +713 -28
  122. package/src/routes/connector-connection-runs.ts +7 -12
  123. package/src/routes/connector-connections.ts +10 -7
  124. package/src/routes/lake.ts +73 -0
  125. package/src/routes/objects.ts +3 -9
  126. package/src/routes/pipelines.ts +1 -0
  127. package/src/routes/shared-access.ts +53 -1
  128. package/src/routes/status.ts +9 -4
  129. package/src/routes/syncs.ts +1 -0
  130. package/src/routes/webhooks.ts +44 -3
  131. package/src/routes/ws/artifacts.ts +138 -0
  132. package/src/routes/ws/events.ts +7 -2
  133. package/src/routes/ws/index.ts +13 -2
  134. package/src/routes/ws/shared-sockets.ts +152 -0
  135. package/src/schemas/agents.ts +11 -0
  136. package/src/schemas/artifacts.ts +255 -18
  137. package/src/schemas/connectors.ts +17 -2
  138. package/src/schemas/files.ts +12 -0
  139. package/src/schemas/lake.ts +53 -0
  140. package/src/schemas/objects.ts +1 -0
  141. package/src/schemas/pipelines.ts +2 -0
  142. package/src/schemas/projections.ts +2 -2
  143. package/src/schemas/shared-access.ts +16 -0
  144. package/src/schemas/status.ts +16 -22
  145. package/src/schemas/syncs.ts +2 -0
  146. package/src/server.ts +35 -4
  147. package/src/utils/ws.ts +7 -0
@@ -96,8 +96,8 @@ export const ObjectProjectionSchema = z.object({
96
96
  objectTypeId: z.string(),
97
97
  datasetId: z.string(),
98
98
  properties: z.record(z.string()),
99
- /** The `ref.user()` properties whose column holds a member's email. */
100
- users: z.record(z.literal("email")).optional(),
99
+ /** The `ref.user()` properties whose column names a member, and whether by email or by id. */
100
+ users: z.record(z.enum(["email", "id"])).optional(),
101
101
  links: z.record(ForeignKeyDescriptorSchema),
102
102
  conflictResolution: SourceEditConflictResolutionSchema,
103
103
  latestRun: ProjectionRunSchema.nullable(),
@@ -24,6 +24,22 @@ export const SharedAccessSessionResponseSchema = z.object({
24
24
  expiresAt: Rfc3339DateSchema,
25
25
  absoluteExpiresAt: Rfc3339DateSchema,
26
26
  csrfToken: z.string().regex(/^[A-Za-z0-9_-]{43}$/),
27
+ guestId: StoredIdentifierSchema.describe(
28
+ "Who the visitor is in this session: the author id of the comments they write as a guest"
29
+ ),
30
+ guestName: z
31
+ .string()
32
+ .optional()
33
+ .describe("The name the visitor gave, which their comments and live presence carry"),
34
+ })
35
+
36
+ export const SetSharedAccessGuestNameBodySchema = z.object({
37
+ name: z
38
+ .string()
39
+ .max(1_000)
40
+ .describe(
41
+ "The visitor's name, on one line: 1 to 60 characters once its spaces are collapsed, without control or direction marks"
42
+ ),
27
43
  })
28
44
 
29
45
  export const SharedAccessSignOutResponseSchema = z.object({
@@ -14,32 +14,26 @@ export const ReadinessResponseSchema = z.object({
14
14
  })
15
15
 
16
16
  const MaintenanceSummarySchema = z.object({
17
- running: z.boolean(),
18
- intervalMs: z.number().int().positive(),
19
- lastStartedAt: z.string().nullable(),
20
- lastCompletedAt: z.string().nullable(),
21
- lastDurationMs: z.number().nonnegative().nullable(),
22
- consecutiveFailures: z.number().int().nonnegative(),
23
- lastError: z.string().nullable(),
24
- outbox: z
25
- .object({
26
- pendingCount: z.number().int().nonnegative(),
27
- oldestPendingAt: z.string().nullable(),
28
- retryingCount: z.number().int().nonnegative(),
29
- maxAttempts: z.number().int().nonnegative(),
17
+ owner: z.enum(["orchestrator", "embedded"]).nullable(),
18
+ beatAt: z.string().nullable(),
19
+ stale: z.boolean(),
20
+ passes: z.array(
21
+ z.object({
22
+ id: z.string(),
23
+ lastSucceededAt: z.string().nullable(),
24
+ consecutiveFailures: z.number().int().nonnegative(),
30
25
  })
31
- .nullable(),
32
- cleanup: z
33
- .object({
34
- publishedOutboxRowsDeleted: z.number().int().nonnegative(),
35
- terminalSourceRowsDeleted: z.number().int().nonnegative(),
36
- terminalSourceMaterializationsDeleted: z.number().int().nonnegative(),
37
- })
38
- .nullable(),
26
+ ),
27
+ outbox: z.object({
28
+ pendingCount: z.number().int().nonnegative(),
29
+ oldestPendingAt: z.string().nullable(),
30
+ retryingCount: z.number().int().nonnegative(),
31
+ maxAttempts: z.number().int().nonnegative(),
32
+ }),
39
33
  })
40
34
 
41
35
  export const StatusResponseSchema = z.object({
42
- status: z.enum(["ok", "degraded"]),
36
+ status: z.enum(["ok", "degraded", "unknown"]),
43
37
  objectTypes: z.number().int().nonnegative(),
44
38
  maintenance: MaintenanceSummarySchema,
45
39
  })
@@ -45,6 +45,8 @@ export const SyncRunSchema = z.object({
45
45
  datasetId: z.string(),
46
46
  mode: SyncModeSchema,
47
47
  status: SyncRunStatusSchema,
48
+ /** How many executions took the run: above one, it resumed after losing its worker. */
49
+ attempt: z.number(),
48
50
  queuedAt: z.string(),
49
51
  startedAt: z.string().optional(),
50
52
  finishedAt: z.string().optional(),
package/src/server.ts CHANGED
@@ -5,7 +5,7 @@ import { bindAgentRunRequestExecution } from "@sixb/core/internal/agent-executio
5
5
  import { ARTIFACT_FRAME_ROUTE_PREFIX } from "@sixb/core/internal/artifacts/frames"
6
6
  import { CSRF_HEADER_NAME, setRequestClientAddress } from "@sixb/core/internal/auth"
7
7
  import { bindRequestExecution } from "@sixb/core/internal/request-execution"
8
- import { setApiPublicOrigin } from "@sixb/core/internal/runtime"
8
+ import { findDatasetIngestRuntime, setApiPublicOrigin } from "@sixb/core/internal/runtime"
9
9
  import { checkPipelineMarkings, warmAppliedMarkings } from "@sixb/core/internal/security"
10
10
  import type { Server } from "bun"
11
11
  import { Elysia, ParseError } from "elysia"
@@ -88,6 +88,16 @@ export interface SixbServerOptions {
88
88
  trustedProxies?: readonly string[]
89
89
  /** Where requests spend their time: a `Server-Timing` header and a log of slow requests. */
90
90
  timing?: SixbRequestTimingOptions
91
+ /**
92
+ * Whether this server delivers the events a commit left undelivered and purges expired records,
93
+ * every minute. Defaults to true; set it to false when an orchestrator runs for the project.
94
+ */
95
+ ontologyMaintenance?: boolean
96
+ /**
97
+ * Whether `sixb.datasets.ingest` in this server writes what it stored before it returns, as no
98
+ * worker will. Defaults to true; set it to false when a lake worker runs for the project.
99
+ */
100
+ ingestFlush?: boolean
91
101
  }
92
102
 
93
103
  export function createSixbServer(options: SixbServerOptions): SixbServer {
@@ -108,6 +118,8 @@ export class SixbServer {
108
118
  private readonly timing: SixbRequestTimingOptions
109
119
  private app: SixbApp | null = null
110
120
  private bunServer: ReturnType<typeof Bun.serve> | null = null
121
+ private readonly hostsOntologyMaintenance: boolean
122
+ private readonly flushesIngestion: boolean
111
123
  private maintenance: OntologyMaintenanceHandle | null = null
112
124
  private stopSweeper: (() => void) | null = null
113
125
 
@@ -117,6 +129,8 @@ export class SixbServer {
117
129
  this.hostname = options.hostname ?? "0.0.0.0"
118
130
  this.quiet = options.quiet ?? false
119
131
  this.timing = options.timing ?? {}
132
+ this.hostsOntologyMaintenance = options.ontologyMaintenance ?? true
133
+ this.flushesIngestion = options.ingestFlush ?? true
120
134
  this.apiBrowserPolicy = resolveApiBrowserPolicy(options.browser)
121
135
  // URLs the API hands to third parties, such as file download URLs, name this origin.
122
136
  if (this.apiBrowserPolicy.publicOrigin) {
@@ -191,7 +205,12 @@ export class SixbServer {
191
205
  // needs them waits for them; reading them now spares that read the wait.
192
206
  warmAppliedMarkings(this.hostRuntime)
193
207
 
194
- const maintenance = await this.hostRuntime.startOntologyMaintenance()
208
+ this.hostRuntime.prepareReadiness()
209
+ this.setIngestFlush(this.flushesIngestion)
210
+
211
+ const maintenance = this.hostsOntologyMaintenance
212
+ ? await this.hostRuntime.startOntologyMaintenance()
213
+ : null
195
214
  this.maintenance = maintenance
196
215
 
197
216
  try {
@@ -206,7 +225,7 @@ export class SixbServer {
206
225
  this.app = null
207
226
  this.bunServer = null
208
227
  this.maintenance = null
209
- await maintenance.stop()
228
+ await maintenance?.stop()
210
229
  const message = error instanceof Error ? error.message : String(error)
211
230
  throw new Error(`[SixbServer] Failed to listen on ${this.hostname}:${this.port}: ${message}`)
212
231
  }
@@ -221,7 +240,13 @@ export class SixbServer {
221
240
  }
222
241
  }
223
242
 
243
+ private setIngestFlush(inline: boolean): void {
244
+ const ingest = findDatasetIngestRuntime(this.hostRuntime)
245
+ if (ingest) ingest.writesInline = inline
246
+ }
247
+
224
248
  async stop(): Promise<void> {
249
+ this.setIngestFlush(false)
225
250
  this.stopSweeper?.()
226
251
  this.stopSweeper = null
227
252
  if (this.bunServer) {
@@ -324,6 +349,7 @@ export function createSixbApi(server: SixbServer) {
324
349
  return {
325
350
  auth: { kind: "allow" as const, session: null },
326
351
  sharedAccessCookies: null,
352
+ sharedSession: null,
327
353
  ...agentState,
328
354
  sixb: bindAgentRunRequestExecution(host, { signal: request.signal, ...runExecution }),
329
355
  }
@@ -336,6 +362,7 @@ export function createSixbApi(server: SixbServer) {
336
362
  return {
337
363
  auth: { kind: "deny" as const, response: shared.response },
338
364
  sharedAccessCookies: null,
365
+ sharedSession: null,
339
366
  sixb: null,
340
367
  }
341
368
  }
@@ -343,6 +370,8 @@ export function createSixbApi(server: SixbServer) {
343
370
  return {
344
371
  auth: { kind: "allow" as const, session: null },
345
372
  sharedAccessCookies: shared.cookies,
373
+ // A socket keeps the session it opened under, to check it still holds.
374
+ sharedSession: shared.context,
346
375
  sixb: bindRequestExecution(host, {
347
376
  request,
348
377
  authorization: {
@@ -363,6 +392,7 @@ export function createSixbApi(server: SixbServer) {
363
392
  return {
364
393
  auth,
365
394
  sharedAccessCookies: null,
395
+ sharedSession: null,
366
396
  sixb:
367
397
  auth.kind === "allow" && !guard.isAuthEnabled()
368
398
  ? bindRequestExecution(host, {
@@ -381,6 +411,7 @@ export function createSixbApi(server: SixbServer) {
381
411
  return {
382
412
  auth,
383
413
  sharedAccessCookies: null,
414
+ sharedSession: null,
384
415
  sixb: bindRequestExecution(host, {
385
416
  request,
386
417
  authorization: { type: "principal", context: authz, credential },
@@ -492,7 +523,7 @@ export function createSixbApi(server: SixbServer) {
492
523
  },
493
524
  })
494
525
  registerWebhookRoutes(app, host)
495
- registerWebSocketRoutes(app, server)
526
+ registerWebSocketRoutes(app, server, sharedAccess)
496
527
 
497
528
  return app
498
529
  }
package/src/utils/ws.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Sixb } from "@sixb/core/internal/request-execution"
2
+ import type { SharedSessionContext } from "@sixb/core/internal/shares"
2
3
 
3
4
  export function safeSend(target: { send: (message: string) => void }, payload: unknown): void {
4
5
  try {
@@ -24,6 +25,12 @@ export function wsRequestSixb(ws: object): Sixb | null {
24
25
  return data?.sixb ?? null
25
26
  }
26
27
 
28
+ /** The shared link's session the WebSocket request was opened under, if one was. */
29
+ export function wsSharedSession(ws: object): SharedSessionContext | null {
30
+ const data = (ws as { data?: { sharedSession?: SharedSessionContext | null } }).data
31
+ return data?.sharedSession ?? null
32
+ }
33
+
27
34
  function parseJson(text: string): unknown {
28
35
  try {
29
36
  return JSON.parse(text)