@sixb/server 0.2.1 → 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 (153) 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 +2876 -667
  10. package/dist/index.js.map +43 -36
  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 +21 -11
  20. package/dist/routes/agent-approvals.d.ts.map +1 -1
  21. package/dist/routes/agent-children.d.ts +4 -4
  22. package/dist/routes/agent-computers.d.ts +146 -1
  23. package/dist/routes/agent-computers.d.ts.map +1 -1
  24. package/dist/routes/agent-runners.d.ts.map +1 -1
  25. package/dist/routes/agents.d.ts +152 -60
  26. package/dist/routes/agents.d.ts.map +1 -1
  27. package/dist/routes/artifact-frames.d.ts +2 -1
  28. package/dist/routes/artifact-frames.d.ts.map +1 -1
  29. package/dist/routes/artifacts.d.ts +1713 -178
  30. package/dist/routes/artifacts.d.ts.map +1 -1
  31. package/dist/routes/auth.d.ts +21 -21
  32. package/dist/routes/connector-connection-runs.d.ts +124 -5
  33. package/dist/routes/connector-connection-runs.d.ts.map +1 -1
  34. package/dist/routes/connector-connections.d.ts +9 -1
  35. package/dist/routes/connector-connections.d.ts.map +1 -1
  36. package/dist/routes/datasets.d.ts +5 -5
  37. package/dist/routes/events.d.ts +4 -4
  38. package/dist/routes/lake.d.ts +91 -0
  39. package/dist/routes/lake.d.ts.map +1 -0
  40. package/dist/routes/links.d.ts +6 -6
  41. package/dist/routes/logs.d.ts +2 -2
  42. package/dist/routes/model-generations.d.ts +2 -2
  43. package/dist/routes/objects.d.ts +6 -6
  44. package/dist/routes/objects.d.ts.map +1 -1
  45. package/dist/routes/observed-agent-threads.d.ts +21 -11
  46. package/dist/routes/observed-agent-threads.d.ts.map +1 -1
  47. package/dist/routes/ontology.d.ts +6 -6
  48. package/dist/routes/pipelines.d.ts +13 -9
  49. package/dist/routes/pipelines.d.ts.map +1 -1
  50. package/dist/routes/projections.d.ts +27 -27
  51. package/dist/routes/share-grants.d.ts +9 -9
  52. package/dist/routes/shared-access.d.ts +57 -2
  53. package/dist/routes/shared-access.d.ts.map +1 -1
  54. package/dist/routes/status.d.ts +11 -15
  55. package/dist/routes/status.d.ts.map +1 -1
  56. package/dist/routes/syncs.d.ts +9 -6
  57. package/dist/routes/syncs.d.ts.map +1 -1
  58. package/dist/routes/telemetry.d.ts +7 -7
  59. package/dist/routes/webhooks.d.ts.map +1 -1
  60. package/dist/routes/workflows.d.ts +14 -14
  61. package/dist/routes/ws/artifacts.d.ts +57 -0
  62. package/dist/routes/ws/artifacts.d.ts.map +1 -0
  63. package/dist/routes/ws/events.d.ts +8 -7
  64. package/dist/routes/ws/events.d.ts.map +1 -1
  65. package/dist/routes/ws/index.d.ts +2 -1
  66. package/dist/routes/ws/index.d.ts.map +1 -1
  67. package/dist/routes/ws/logs.d.ts +10 -10
  68. package/dist/routes/ws/shared-sockets.d.ts +52 -0
  69. package/dist/routes/ws/shared-sockets.d.ts.map +1 -0
  70. package/dist/schemas/actions.d.ts +7 -7
  71. package/dist/schemas/activity.d.ts +16 -16
  72. package/dist/schemas/agent-approvals.d.ts +27 -27
  73. package/dist/schemas/agents.d.ts +642 -196
  74. package/dist/schemas/agents.d.ts.map +1 -1
  75. package/dist/schemas/ai-accounting.d.ts +41 -41
  76. package/dist/schemas/ai-accounting.d.ts.map +1 -1
  77. package/dist/schemas/artifacts.d.ts +2106 -127
  78. package/dist/schemas/artifacts.d.ts.map +1 -1
  79. package/dist/schemas/auth.d.ts +63 -63
  80. package/dist/schemas/connectors.d.ts +180 -20
  81. package/dist/schemas/connectors.d.ts.map +1 -1
  82. package/dist/schemas/datasets.d.ts +44 -44
  83. package/dist/schemas/event-payloads.d.ts +2 -2
  84. package/dist/schemas/events.d.ts +26 -26
  85. package/dist/schemas/events.d.ts.map +1 -1
  86. package/dist/schemas/files.d.ts +12 -0
  87. package/dist/schemas/files.d.ts.map +1 -1
  88. package/dist/schemas/lake.d.ts +251 -0
  89. package/dist/schemas/lake.d.ts.map +1 -0
  90. package/dist/schemas/lineage.d.ts +56 -56
  91. package/dist/schemas/logs.d.ts +18 -18
  92. package/dist/schemas/models.d.ts +4 -4
  93. package/dist/schemas/objects.d.ts.map +1 -1
  94. package/dist/schemas/ontology.d.ts +14 -14
  95. package/dist/schemas/pipelines.d.ts +86 -64
  96. package/dist/schemas/pipelines.d.ts.map +1 -1
  97. package/dist/schemas/projections.d.ts +160 -160
  98. package/dist/schemas/projections.d.ts.map +1 -1
  99. package/dist/schemas/share-grants.d.ts +30 -30
  100. package/dist/schemas/shared-access.d.ts +17 -4
  101. package/dist/schemas/shared-access.d.ts.map +1 -1
  102. package/dist/schemas/status.d.ts +59 -79
  103. package/dist/schemas/status.d.ts.map +1 -1
  104. package/dist/schemas/syncs.d.ts +38 -22
  105. package/dist/schemas/syncs.d.ts.map +1 -1
  106. package/dist/schemas/telemetry.d.ts +26 -26
  107. package/dist/schemas/workflows.d.ts +71 -71
  108. package/dist/server.d.ts +13 -0
  109. package/dist/server.d.ts.map +1 -1
  110. package/dist/utils/ws.d.ts +3 -0
  111. package/dist/utils/ws.d.ts.map +1 -1
  112. package/package.json +11 -7
  113. package/src/artifacts/frame.ts +4 -13
  114. package/src/auth/scope.ts +10 -1
  115. package/src/auth/shared-access.ts +108 -12
  116. package/src/connectors/http.ts +35 -1
  117. package/src/live/README.md +136 -0
  118. package/src/live/awareness.ts +141 -0
  119. package/src/live/room.ts +933 -0
  120. package/src/live/rooms.ts +288 -0
  121. package/src/registerRoutes.ts +2 -0
  122. package/src/routes/agent-computers.ts +208 -14
  123. package/src/routes/agent-runners.ts +1 -0
  124. package/src/routes/agents.ts +52 -7
  125. package/src/routes/artifact-frames.ts +40 -12
  126. package/src/routes/artifacts.ts +713 -28
  127. package/src/routes/connector-connection-runs.ts +7 -12
  128. package/src/routes/connector-connections.ts +10 -7
  129. package/src/routes/lake.ts +73 -0
  130. package/src/routes/objects.ts +3 -9
  131. package/src/routes/pipelines.ts +1 -0
  132. package/src/routes/shared-access.ts +53 -1
  133. package/src/routes/status.ts +9 -4
  134. package/src/routes/syncs.ts +1 -0
  135. package/src/routes/webhooks.ts +44 -3
  136. package/src/routes/ws/artifacts.ts +138 -0
  137. package/src/routes/ws/events.ts +7 -2
  138. package/src/routes/ws/index.ts +13 -2
  139. package/src/routes/ws/shared-sockets.ts +152 -0
  140. package/src/schemas/agents.ts +71 -1
  141. package/src/schemas/ai-accounting.ts +1 -0
  142. package/src/schemas/artifacts.ts +255 -18
  143. package/src/schemas/connectors.ts +17 -2
  144. package/src/schemas/files.ts +12 -0
  145. package/src/schemas/lake.ts +53 -0
  146. package/src/schemas/objects.ts +1 -0
  147. package/src/schemas/pipelines.ts +2 -0
  148. package/src/schemas/projections.ts +2 -2
  149. package/src/schemas/shared-access.ts +16 -0
  150. package/src/schemas/status.ts +16 -22
  151. package/src/schemas/syncs.ts +2 -0
  152. package/src/server.ts +35 -4
  153. package/src/utils/ws.ts +7 -0
@@ -83,6 +83,18 @@ export const CompleteFileUploadBodySchema = z.object({
83
83
  parts: z.array(FileUploadPartSchema).optional(),
84
84
  })
85
85
 
86
+ /**
87
+ * The grant a shared link's session names in the query of what a browser loads by itself, such as
88
+ * an `<img>`, which cannot send the header. The boundary reads it before routing; a route declares
89
+ * it to keep it in the OpenAPI contract and through query validation.
90
+ */
91
+ export const ShareGrantQuerySchema = z.object({
92
+ shareGrant: z
93
+ .string()
94
+ .optional()
95
+ .describe("Share grant selector for elements that cannot send the x-sixb-share-grant header"),
96
+ })
97
+
86
98
  export const FileContentQuerySchema = z.object({
87
99
  path: z.string().min(1),
88
100
  disposition: z.enum(["inline", "attachment"]).optional(),
@@ -0,0 +1,53 @@
1
+ import { z } from "zod"
2
+
3
+ const DatasetStorageWarningSchema = z.object({
4
+ code: z.enum(["partitioned-small-dataset"]),
5
+ message: z.string(),
6
+ })
7
+
8
+ export const DatasetStorageHealthSchema = z.object({
9
+ datasetId: z.string(),
10
+ materialized: z.boolean().describe("Whether the dataset has a table in the lake"),
11
+ rowCount: z.number().int(),
12
+ dataFiles: z.number().int().describe("Data files its current rows are read from"),
13
+ smallDataFiles: z.number().int().describe("Data files small enough that compaction merges them"),
14
+ dataBytes: z.number().int(),
15
+ deleteFiles: z.number().int().describe("Files listing deleted rows, until compaction"),
16
+ inlinedRows: z.number().int().describe("Rows kept in the catalog rather than in files"),
17
+ retainedSnapshots: z.number().int().describe("Commits still in the dataset's history"),
18
+ partitionBy: z.array(z.string()),
19
+ warnings: z.array(DatasetStorageWarningSchema),
20
+ ingest: z
21
+ .object({
22
+ pendingDeliveries: z.number().int(),
23
+ pendingChanges: z.number().int(),
24
+ oldestReceivedAt: z
25
+ .string()
26
+ .datetime()
27
+ .nullable()
28
+ .describe("When the oldest waiting delivery arrived"),
29
+ rejectedDeliveries: z
30
+ .number()
31
+ .int()
32
+ .describe("Deliveries refused when written, kept for a week to read and send again"),
33
+ })
34
+ .nullable()
35
+ .describe("Ingested changes waiting or refused; null when there are none"),
36
+ })
37
+
38
+ export const LakeHealthResponseSchema = z.object({
39
+ available: z.boolean().describe("Whether the lake storage provider supports maintenance"),
40
+ cleanup: z.object({
41
+ state: z
42
+ .enum(["off", "idle", "not-requested", "no-worker", "failing", "cleaning", "ok"])
43
+ .describe(
44
+ "What actually happens: `not-requested` when no orchestrator asks, `no-worker` when no lake worker runs what it asks"
45
+ ),
46
+ lastRequestedAt: z.string().nullable().describe("When the orchestrator last asked for cleanup"),
47
+ lastRunAt: z.string().nullable().describe("When a lake worker last started a cleanup"),
48
+ keepVersionsFor: z.string(),
49
+ deleteFilesAfter: z.string(),
50
+ cleanupEvery: z.string(),
51
+ }),
52
+ datasets: z.array(DatasetStorageHealthSchema),
53
+ })
@@ -686,6 +686,7 @@ export const ObjectQueryOpenApiSchemas: OpenApiSchemas = {
686
686
  "uuid",
687
687
  "fileRef",
688
688
  "userRef",
689
+ "artifactRef",
689
690
  "enum",
690
691
  "array",
691
692
  "object",
@@ -63,6 +63,8 @@ export const PipelineRunSchema = z.object({
63
63
  projectId: z.string(),
64
64
  pipelineId: z.string(),
65
65
  status: PipelineRunStatusSchema,
66
+ /** How many executions took the run: above one, it resumed after losing its worker. */
67
+ attempt: z.number(),
66
68
  queuedAt: z.string(),
67
69
  startedAt: z.string().optional(),
68
70
  finishedAt: z.string().optional(),
@@ -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)