@sixb/server 0.1.1 → 0.1.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 (178) 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/experience.d.ts +33 -0
  7. package/dist/auth/experience.d.ts.map +1 -0
  8. package/dist/auth/guard.d.ts +3 -3
  9. package/dist/auth/guard.d.ts.map +1 -1
  10. package/dist/auth/public-routes.d.ts.map +1 -1
  11. package/dist/auth/scope.d.ts +13 -27
  12. package/dist/auth/scope.d.ts.map +1 -1
  13. package/dist/auth/session-cookies.d.ts +2 -2
  14. package/dist/auth/session-cookies.d.ts.map +1 -1
  15. package/dist/connectors/http.d.ts +16 -0
  16. package/dist/connectors/http.d.ts.map +1 -0
  17. package/dist/index.d.ts +1 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +3903 -2760
  20. package/dist/index.js.map +58 -50
  21. package/dist/openapi/tags.d.ts +15 -3
  22. package/dist/openapi/tags.d.ts.map +1 -1
  23. package/dist/registerRoutes.d.ts +6 -2
  24. package/dist/registerRoutes.d.ts.map +1 -1
  25. package/dist/routes/action-runs.d.ts +21 -31
  26. package/dist/routes/action-runs.d.ts.map +1 -1
  27. package/dist/routes/actions.d.ts +12 -11
  28. package/dist/routes/actions.d.ts.map +1 -1
  29. package/dist/routes/agent-api-gateway.d.ts +2 -2
  30. package/dist/routes/agent-api-gateway.d.ts.map +1 -1
  31. package/dist/routes/agents.d.ts +230 -159
  32. package/dist/routes/agents.d.ts.map +1 -1
  33. package/dist/routes/ai-accounting.d.ts +31 -0
  34. package/dist/routes/ai-accounting.d.ts.map +1 -0
  35. package/dist/routes/auth.d.ts +149 -92
  36. package/dist/routes/auth.d.ts.map +1 -1
  37. package/dist/routes/connector-connection-runs.d.ts +794 -0
  38. package/dist/routes/connector-connection-runs.d.ts.map +1 -0
  39. package/dist/routes/connector-connections.d.ts +219 -0
  40. package/dist/routes/connector-connections.d.ts.map +1 -0
  41. package/dist/routes/connectors.d.ts +10 -4
  42. package/dist/routes/connectors.d.ts.map +1 -1
  43. package/dist/routes/datasets.d.ts +16 -12
  44. package/dist/routes/datasets.d.ts.map +1 -1
  45. package/dist/routes/events.d.ts +9 -9
  46. package/dist/routes/events.d.ts.map +1 -1
  47. package/dist/routes/files.d.ts +19 -18
  48. package/dist/routes/files.d.ts.map +1 -1
  49. package/dist/routes/links.d.ts +11 -11
  50. package/dist/routes/links.d.ts.map +1 -1
  51. package/dist/routes/logs.d.ts +5 -5
  52. package/dist/routes/logs.d.ts.map +1 -1
  53. package/dist/routes/objects.d.ts +37 -37
  54. package/dist/routes/objects.d.ts.map +1 -1
  55. package/dist/routes/ontology.d.ts +50 -50
  56. package/dist/routes/ontology.d.ts.map +1 -1
  57. package/dist/routes/pipelines.d.ts +28 -38
  58. package/dist/routes/pipelines.d.ts.map +1 -1
  59. package/dist/routes/project.d.ts +2 -2
  60. package/dist/routes/project.d.ts.map +1 -1
  61. package/dist/routes/projections.d.ts +145 -85
  62. package/dist/routes/projections.d.ts.map +1 -1
  63. package/dist/routes/rules.d.ts +6 -6
  64. package/dist/routes/rules.d.ts.map +1 -1
  65. package/dist/routes/status.d.ts +2 -2
  66. package/dist/routes/status.d.ts.map +1 -1
  67. package/dist/routes/syncs.d.ts +23 -28
  68. package/dist/routes/syncs.d.ts.map +1 -1
  69. package/dist/routes/telemetry.d.ts +9 -9
  70. package/dist/routes/telemetry.d.ts.map +1 -1
  71. package/dist/routes/webhook-runs.d.ts +9 -9
  72. package/dist/routes/webhook-runs.d.ts.map +1 -1
  73. package/dist/routes/webhooks.d.ts +2 -2
  74. package/dist/routes/webhooks.d.ts.map +1 -1
  75. package/dist/routes/workflows.d.ts +177 -66
  76. package/dist/routes/workflows.d.ts.map +1 -1
  77. package/dist/routes/ws/agents.d.ts +11 -5
  78. package/dist/routes/ws/agents.d.ts.map +1 -1
  79. package/dist/routes/ws/events.d.ts +8 -8
  80. package/dist/routes/ws/events.d.ts.map +1 -1
  81. package/dist/routes/ws/log-subscription-hub.d.ts +6 -3
  82. package/dist/routes/ws/log-subscription-hub.d.ts.map +1 -1
  83. package/dist/routes/ws/logs.d.ts +10 -10
  84. package/dist/routes/ws/logs.d.ts.map +1 -1
  85. package/dist/schemas/actions.d.ts +89 -194
  86. package/dist/schemas/actions.d.ts.map +1 -1
  87. package/dist/schemas/agents.d.ts +791 -471
  88. package/dist/schemas/agents.d.ts.map +1 -1
  89. package/dist/schemas/ai-accounting.d.ts +2393 -0
  90. package/dist/schemas/ai-accounting.d.ts.map +1 -0
  91. package/dist/schemas/ai-usage.d.ts +34 -0
  92. package/dist/schemas/ai-usage.d.ts.map +1 -0
  93. package/dist/schemas/auth.d.ts +102 -102
  94. package/dist/schemas/common.d.ts +37 -0
  95. package/dist/schemas/common.d.ts.map +1 -1
  96. package/dist/schemas/connectors.d.ts +713 -2
  97. package/dist/schemas/connectors.d.ts.map +1 -1
  98. package/dist/schemas/datasets.d.ts +2 -2
  99. package/dist/schemas/event-payloads.d.ts +12 -12
  100. package/dist/schemas/events.d.ts +40 -40
  101. package/dist/schemas/links.d.ts +2 -2
  102. package/dist/schemas/logs.d.ts +22 -22
  103. package/dist/schemas/objects.d.ts +10 -10
  104. package/dist/schemas/ontology.d.ts +118 -118
  105. package/dist/schemas/pipelines.d.ts +89 -184
  106. package/dist/schemas/pipelines.d.ts.map +1 -1
  107. package/dist/schemas/projections.d.ts +1030 -563
  108. package/dist/schemas/projections.d.ts.map +1 -1
  109. package/dist/schemas/rules.d.ts +6 -6
  110. package/dist/schemas/syncs.d.ts +65 -108
  111. package/dist/schemas/syncs.d.ts.map +1 -1
  112. package/dist/schemas/webhook-runs.d.ts +41 -41
  113. package/dist/schemas/webhook-runs.d.ts.map +1 -1
  114. package/dist/schemas/workflows.d.ts +1189 -185
  115. package/dist/schemas/workflows.d.ts.map +1 -1
  116. package/dist/server.d.ts +11 -6
  117. package/dist/server.d.ts.map +1 -1
  118. package/dist/utils/http.d.ts +2 -0
  119. package/dist/utils/http.d.ts.map +1 -1
  120. package/dist/utils/ws.d.ts +4 -3
  121. package/dist/utils/ws.d.ts.map +1 -1
  122. package/package.json +5 -5
  123. package/src/auth/access-token-boundary.ts +4 -4
  124. package/src/auth/application-access.ts +8 -9
  125. package/src/auth/connector-callback-cookie.ts +95 -0
  126. package/src/auth/experience.ts +190 -0
  127. package/src/auth/guard.ts +11 -11
  128. package/src/auth/public-routes.ts +20 -0
  129. package/src/auth/scope.ts +26 -36
  130. package/src/auth/session-cookies.ts +3 -3
  131. package/src/connectors/http.ts +110 -0
  132. package/src/index.ts +1 -0
  133. package/src/openapi/tags.ts +13 -1
  134. package/src/registerRoutes.ts +36 -23
  135. package/src/routes/action-runs.ts +39 -39
  136. package/src/routes/actions.ts +7 -13
  137. package/src/routes/agent-api-gateway.ts +41 -38
  138. package/src/routes/agents.ts +90 -200
  139. package/src/routes/ai-accounting.ts +166 -0
  140. package/src/routes/auth.ts +274 -122
  141. package/src/routes/connector-connection-runs.ts +346 -0
  142. package/src/routes/connector-connections.ts +135 -0
  143. package/src/routes/connectors.ts +24 -12
  144. package/src/routes/datasets.ts +55 -54
  145. package/src/routes/events.ts +5 -5
  146. package/src/routes/files.ts +22 -30
  147. package/src/routes/links.ts +31 -35
  148. package/src/routes/logs.ts +6 -11
  149. package/src/routes/objects.ts +51 -114
  150. package/src/routes/ontology.ts +27 -38
  151. package/src/routes/pipelines.ts +28 -62
  152. package/src/routes/project.ts +3 -3
  153. package/src/routes/projections.ts +44 -42
  154. package/src/routes/rules.ts +11 -25
  155. package/src/routes/status.ts +5 -5
  156. package/src/routes/syncs.ts +19 -45
  157. package/src/routes/telemetry.ts +18 -29
  158. package/src/routes/webhook-runs.ts +5 -5
  159. package/src/routes/webhooks.ts +259 -341
  160. package/src/routes/workflows.ts +242 -248
  161. package/src/routes/ws/agents.ts +196 -66
  162. package/src/routes/ws/events.ts +11 -10
  163. package/src/routes/ws/log-subscription-hub.ts +6 -12
  164. package/src/routes/ws/logs.ts +13 -5
  165. package/src/schemas/actions.ts +58 -25
  166. package/src/schemas/agents.ts +23 -23
  167. package/src/schemas/ai-accounting.ts +182 -0
  168. package/src/schemas/ai-usage.ts +16 -0
  169. package/src/schemas/common.ts +24 -0
  170. package/src/schemas/connectors.ts +164 -0
  171. package/src/schemas/pipelines.ts +23 -15
  172. package/src/schemas/projections.ts +23 -3
  173. package/src/schemas/syncs.ts +13 -8
  174. package/src/schemas/webhook-runs.ts +10 -5
  175. package/src/schemas/workflows.ts +23 -8
  176. package/src/server.ts +75 -26
  177. package/src/utils/http.ts +34 -6
  178. package/src/utils/ws.ts +10 -5
@@ -1,8 +1,13 @@
1
+ import type { SixbFailure } from "@sixb/core"
2
+ import type { WebhookRunFailureCode } from "@sixb/core/storage"
3
+ import { WEBHOOK_RUN_FAILURE_CODES } from "@sixb/core/storage"
1
4
  import { z } from "zod"
5
+ import { sixbFailureSchema } from "./common"
2
6
 
3
- export const WebhookRunStatusSchema = z.enum(["running", "succeeded", "failed", "skipped"])
7
+ const WebhookRunFailureSchema: z.ZodType<SixbFailure<WebhookRunFailureCode>> =
8
+ sixbFailureSchema(WEBHOOK_RUN_FAILURE_CODES)
4
9
 
5
- export const WebhookDeliveryClaimResultSchema = z.enum(["claimed", "duplicate", "in_progress"])
10
+ export const WebhookRunStatusSchema = z.enum(["running", "succeeded", "failed"])
6
11
 
7
12
  export const WebhookRunsQuerySchema = z.object({
8
13
  connectorId: z.string().optional(),
@@ -19,6 +24,7 @@ export const WebhookRunsQuerySchema = z.object({
19
24
  export const WebhookRunSchema = z.object({
20
25
  id: z.string(),
21
26
  projectId: z.string(),
27
+ executionId: z.string(),
22
28
  connectorId: z.string(),
23
29
  webhookId: z.string(),
24
30
  status: WebhookRunStatusSchema,
@@ -26,11 +32,10 @@ export const WebhookRunSchema = z.object({
26
32
  route: z.string(),
27
33
  startedAt: z.string(),
28
34
  finishedAt: z.string().optional(),
29
- requestBodyBytes: z.number().optional(),
35
+ requestBodyBytes: z.number(),
30
36
  responseStatus: z.number().optional(),
31
37
  idempotencyKey: z.string().optional(),
32
- deliveryClaimResult: WebhookDeliveryClaimResultSchema.optional(),
33
- error: z.string().optional(),
38
+ error: WebhookRunFailureSchema.optional(),
34
39
  })
35
40
 
36
41
  export const WebhookRunListResponseSchema = z.object({
@@ -1,8 +1,20 @@
1
+ import {
2
+ type SixbFailure,
3
+ WORKFLOW_RUN_FAILURE_CODES,
4
+ type WorkflowRunFailureCode,
5
+ } from "@sixb/core/storage"
1
6
  import { z } from "zod"
2
- import { JsonValueSchema } from "./common"
7
+ import { AgentMessagePartSchema, AgentRunFailureSchema } from "./agents"
8
+ import { AiCostSummarySchema } from "./ai-accounting"
9
+ import { AiUsageSummarySchema } from "./ai-usage"
10
+ import { JsonValueSchema, sixbFailureSchema } from "./common"
3
11
 
4
12
  export const WorkflowIOSnapshotSchema = z.record(JsonValueSchema)
5
13
 
14
+ const WorkflowRunFailureSchema: z.ZodType<SixbFailure<WorkflowRunFailureCode>> = sixbFailureSchema(
15
+ WORKFLOW_RUN_FAILURE_CODES
16
+ )
17
+
6
18
  export const WorkflowParamsSchema = z.object({
7
19
  workflowId: z.string().min(1),
8
20
  })
@@ -121,7 +133,7 @@ export const WorkflowRunSummarySchema = z.object({
121
133
  queuedAt: z.string().optional(),
122
134
  startedAt: z.string(),
123
135
  finishedAt: z.string().optional(),
124
- error: z.string().optional(),
136
+ error: WorkflowRunFailureSchema.optional(),
125
137
  requestedBy: WorkflowInterventionActorSchema,
126
138
  })
127
139
 
@@ -136,18 +148,21 @@ export const WorkflowAgentNodeExecutionSummarySchema = z.object({
136
148
  attempt: z.number().int().nonnegative(),
137
149
  modelId: z.string().optional(),
138
150
  finishReason: z.string().optional(),
139
- usage: z.record(z.unknown()).optional(),
151
+ usage: AiUsageSummarySchema.optional(),
152
+ cost: AiCostSummarySchema.optional(),
140
153
  startedAt: z.string().optional(),
141
154
  completedAt: z.string().optional(),
142
155
  })
143
156
 
157
+ export const WorkflowAgentFailurePhaseSchema = z.enum(["agent-loop", "structured-finalizer"])
158
+
144
159
  export const WorkflowAgentNodeExecutionSchema = WorkflowAgentNodeExecutionSummarySchema.extend({
145
160
  nodeRunId: z.string(),
146
161
  prompt: z.string(),
147
- executionPrincipal: WorkflowInterventionActorSchema.optional(),
148
- trace: z.array(z.unknown()).optional(),
149
- diagnostics: z.array(z.unknown()).optional(),
150
- error: z.string().optional(),
162
+ trace: z.array(AgentMessagePartSchema).optional(),
163
+ diagnostics: z.array(JsonValueSchema).optional(),
164
+ failurePhase: WorkflowAgentFailurePhaseSchema.optional(),
165
+ error: AgentRunFailureSchema.optional(),
151
166
  createdAt: z.string(),
152
167
  })
153
168
 
@@ -165,7 +180,7 @@ export const WorkflowNodeRunSchema = z.object({
165
180
  startedAt: z.string(),
166
181
  finishedAt: z.string().optional(),
167
182
  output: WorkflowIOSnapshotSchema.optional(),
168
- error: z.string().optional(),
183
+ error: WorkflowRunFailureSchema.optional(),
169
184
  agentExecution: WorkflowAgentNodeExecutionSummarySchema.optional(),
170
185
  })
171
186
 
package/src/server.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { cors } from "@elysiajs/cors"
2
2
  import { openapi } from "@elysiajs/openapi"
3
- import type { OntologyMaintenanceHandle, OntologySource, Sixb } from "@sixb/core"
3
+ import type { OntologyMaintenanceHandle, SixbHostView } from "@sixb/core"
4
4
  import { CSRF_HEADER_NAME } from "@sixb/core/internal/auth"
5
+ import { bindRequestExecution } from "@sixb/core/internal/request-execution"
5
6
  import { Elysia } from "elysia"
6
7
  import { websocket as elysiaWebSocket } from "elysia/ws"
7
8
  import { zodToJsonSchema } from "zod-to-json-schema"
@@ -24,6 +25,7 @@ import {
24
25
  type SixbApiBrowserPolicy,
25
26
  } from "./auth/browser-origin"
26
27
  import { CSRF_TOKEN_RESPONSE_HEADER_NAME } from "./auth/csrf"
28
+ import type { SixbAuthExperienceOptions } from "./auth/experience"
27
29
  import { ServerAuthGuard } from "./auth/guard"
28
30
  import { consumeInternalRequestAuthState } from "./auth/scope"
29
31
  import { SESSION_ACTIVITY_HEADER_NAME } from "./auth/session-activity"
@@ -43,11 +45,13 @@ import { jsonValueOpenApiOverride } from "./schemas/common"
43
45
  import { ObjectQueryOpenApiSchemas } from "./schemas/objects"
44
46
 
45
47
  export interface SixbServerOptions {
46
- sixb: Sixb<readonly OntologySource[]>
48
+ host: SixbHostView
47
49
  port?: number
48
- host?: string
50
+ hostname?: string
49
51
  quiet?: boolean
50
52
  browser: SixbApiBrowserPolicy
53
+ /** Optional custom-app auth bundle mounted under the API's `/auth` routes. */
54
+ authExperience?: SixbAuthExperienceOptions
51
55
  }
52
56
 
53
57
  export function createSixbServer(options: SixbServerOptions): SixbServer {
@@ -55,31 +59,33 @@ export function createSixbServer(options: SixbServerOptions): SixbServer {
55
59
  }
56
60
 
57
61
  export class SixbServer {
58
- private readonly sixb: Sixb<readonly OntologySource[]>
62
+ private readonly hostRuntime: SixbHostView
59
63
  private readonly port: number
60
- private readonly host: string
64
+ private readonly hostname: string
61
65
  private readonly quiet: boolean
62
66
  private readonly apiBrowserPolicy: ResolvedSixbApiBrowserPolicy
63
67
  private readonly authContextResolver: ResolveRequestAuthContext
64
68
  private readonly authRedirectContextResolver: ResolveAuthRedirectContext
69
+ private readonly authExperience?: SixbAuthExperienceOptions
65
70
  private app: SixbApp | null = null
66
71
  private bunServer: ReturnType<typeof Bun.serve> | null = null
67
72
  private maintenance: OntologyMaintenanceHandle | null = null
68
73
 
69
74
  constructor(options: SixbServerOptions) {
70
- this.sixb = options.sixb
75
+ this.hostRuntime = options.host
71
76
  this.port = options.port ?? 3000
72
- this.host = options.host ?? "0.0.0.0"
77
+ this.hostname = options.hostname ?? "0.0.0.0"
73
78
  this.quiet = options.quiet ?? false
74
79
  this.apiBrowserPolicy = resolveApiBrowserPolicy(options.browser)
75
80
  this.authContextResolver = createApiBrowserAuthContextResolver(this.apiBrowserPolicy)
76
81
  this.authRedirectContextResolver = createApiBrowserAuthRedirectContextResolver(
77
82
  this.apiBrowserPolicy
78
83
  )
84
+ this.authExperience = options.authExperience
79
85
  }
80
86
 
81
- getSixb(): Sixb<readonly OntologySource[]> {
82
- return this.sixb
87
+ getHost(): SixbHostView {
88
+ return this.hostRuntime
83
89
  }
84
90
 
85
91
  getPort(): number {
@@ -116,18 +122,22 @@ export class SixbServer {
116
122
  return this.apiBrowserPolicy
117
123
  }
118
124
 
125
+ getAuthExperience(): SixbAuthExperienceOptions | undefined {
126
+ return this.authExperience
127
+ }
128
+
119
129
  async start(): Promise<void> {
120
130
  if (this.app !== null || this.bunServer !== null || this.maintenance !== null) {
121
131
  throw new Error("[SixbServer] Server is already running.")
122
132
  }
123
133
 
124
- const maintenance = await this.sixb.startOntologyMaintenance()
134
+ const maintenance = await this.hostRuntime.startOntologyMaintenance()
125
135
  this.maintenance = maintenance
126
136
 
127
137
  try {
128
138
  this.app = createSixbApi(this)
129
139
  this.bunServer = startApiServer(this.app, {
130
- host: this.host,
140
+ host: this.hostname,
131
141
  port: this.port,
132
142
  })
133
143
  } catch (error) {
@@ -136,11 +146,11 @@ export class SixbServer {
136
146
  this.maintenance = null
137
147
  await maintenance.stop()
138
148
  const message = error instanceof Error ? error.message : String(error)
139
- throw new Error(`[SixbServer] Failed to listen on ${this.host}:${this.port}: ${message}`)
149
+ throw new Error(`[SixbServer] Failed to listen on ${this.hostname}:${this.port}: ${message}`)
140
150
  }
141
151
 
142
152
  if (!this.quiet) {
143
- const base = `http://${this.host}:${this.port}`
153
+ const base = `http://${this.hostname}:${this.port}`
144
154
  console.log(`Sixb server running at ${base}`)
145
155
  console.log(`OpenAPI docs at ${base}/docs`)
146
156
  }
@@ -164,9 +174,9 @@ export class SixbServer {
164
174
  }
165
175
 
166
176
  export function createSixbApi(server: SixbServer) {
167
- const sixb = server.getSixb()
177
+ const host = server.getHost()
168
178
  const guard = new ServerAuthGuard({
169
- sixb,
179
+ host,
170
180
  resolveAuthContext: (request) => server.resolveAuthContext(request),
171
181
  })
172
182
  guard.assertCanServeHttp({ production: process.env.NODE_ENV === "production" })
@@ -196,23 +206,49 @@ export function createSixbApi(server: SixbServer) {
196
206
  })
197
207
  )
198
208
 
199
- // Resolve the session once per request and attach the principal's scoped SDK.
200
- // The beforeHandle enforces the auth decision before any route runs; `scoped`
201
- // and `authz` stay null for public routes and disabled auth (privileged mode).
209
+ // Resolve authentication and bind one execution SDK at the request boundary. Protected routes
210
+ // never choose between a principal SDK and the ambient runtime themselves.
202
211
  app
203
212
  .derive(async ({ request }) => {
204
213
  const internalAuthState = consumeInternalRequestAuthState(request)
205
214
  if (internalAuthState) {
206
- return { auth: { kind: "allow" as const, session: null }, ...internalAuthState }
215
+ const { authorization, ...agentState } = internalAuthState
216
+ return {
217
+ auth: { kind: "allow" as const, session: null },
218
+ ...agentState,
219
+ sixb: bindRequestExecution(host, {
220
+ request,
221
+ authorization,
222
+ }),
223
+ }
207
224
  }
208
225
 
209
226
  const auth = await guard.resolve(request)
210
227
  if (auth.kind === "deny" || !auth.session?.authenticated) {
211
- return { auth, authz: null, scoped: null }
228
+ return {
229
+ auth,
230
+ sixb:
231
+ auth.kind === "allow" && !guard.isAuthEnabled()
232
+ ? bindRequestExecution(host, {
233
+ request,
234
+ authorization: { type: "disabled" },
235
+ })
236
+ : null,
237
+ }
212
238
  }
213
239
 
214
- const authz = sixb.auth.contextFromSession(auth.session)
215
- return { auth, authz, scoped: sixb.as(authz) }
240
+ const authz = host.auth.contextFromSession(auth.session)
241
+ const credential =
242
+ auth.session.credentialSource === "session"
243
+ ? { type: "session" as const, id: auth.session.session.id }
244
+ : { type: "accessToken" as const, id: auth.session.accessToken.id }
245
+ return {
246
+ auth,
247
+ sixb: bindRequestExecution(host, {
248
+ request,
249
+ authorization: { type: "principal", context: authz, credential },
250
+ }),
251
+ }
216
252
  })
217
253
  .onBeforeHandle(({ auth }) => (auth.kind === "deny" ? auth.response : undefined))
218
254
  .mapResponse(({ auth, request, set }) => {
@@ -226,7 +262,7 @@ export function createSixbApi(server: SixbServer) {
226
262
  }
227
263
 
228
264
  const renewal = createSessionRenewalCookieHeaders({
229
- sixb,
265
+ host: host,
230
266
  request,
231
267
  session: auth.session,
232
268
  })
@@ -271,17 +307,30 @@ export function createSixbApi(server: SixbServer) {
271
307
  })
272
308
  )
273
309
 
274
- registerAuthRoutes(app, sixb, {
310
+ registerAuthRoutes(app, host, {
275
311
  resolveAuthContext: (request) => server.resolveAuthContext(request),
276
312
  resolveAuthRedirectContext: (request, input) =>
277
313
  server.resolveAuthRedirectContext(request, input),
278
314
  getInvitationDestinationOptions: (request) => server.getInvitationDestinationOptions(request),
279
315
  resolveAuthRequestOrigin: (request) => server.resolveAuthRequestOrigin(request),
316
+ authExperience: server.getAuthExperience(),
280
317
  resolveInvitationRedirectContext: (request, input) =>
281
318
  server.resolveInvitationRedirectContext(request, input),
282
319
  })
283
- registerHttpRoutes(app, sixb)
284
- registerWebhookRoutes(app, sixb)
320
+ registerHttpRoutes(app, host, {
321
+ connectorConnections: {
322
+ resolveReturnTo: (request, returnTo) => {
323
+ const authContext = server.resolveAuthContext(request)
324
+ return server.resolveAuthRedirectContext(request, {
325
+ audience: authContext.audience,
326
+ returnTo,
327
+ }).returnTo
328
+ },
329
+ resolveCallbackUrl: (request) =>
330
+ new URL("/auth/connectors/callback", server.resolveAuthRequestOrigin(request)).toString(),
331
+ },
332
+ })
333
+ registerWebhookRoutes(app, host)
285
334
  registerWebSocketRoutes(app, server)
286
335
 
287
336
  return app
package/src/utils/http.ts CHANGED
@@ -1,4 +1,10 @@
1
- import { AuthorizationError, OntologyNotFoundError, OntologyValidationError } from "@sixb/core"
1
+ import {
2
+ AuthorizationError,
3
+ OntologyNotFoundError,
4
+ OntologyValidationError,
5
+ type SixbErrorCode,
6
+ } from "@sixb/core"
7
+ import { isSixbError } from "@sixb/core/internal/errors"
2
8
  import {
3
9
  FileUploadSessionError,
4
10
  type FileUploadSessionErrorReason,
@@ -6,6 +12,24 @@ import {
6
12
  } from "@sixb/core/storage"
7
13
  import { RequestBodyTooLargeError } from "./request-body"
8
14
 
15
+ /** Explicit transport policy for coded failures that are safe to surface as non-500 responses. */
16
+ const HTTP_STATUS_BY_ERROR_CODE: Partial<Record<SixbErrorCode, number>> = {
17
+ "connector.adapter_invalid": 502,
18
+ "connector.authorization_invalid": 400,
19
+ "connector.authorization_required": 409,
20
+ "connector.configuration_invalid": 400,
21
+ "connector.credentials_unavailable": 503,
22
+ "connector.not_found": 404,
23
+ "connector.operation_conflict": 409,
24
+ "connector.operation_in_progress": 409,
25
+ "connector.provider_failed": 502,
26
+ "connector.provider_unavailable": 503,
27
+ "connector.replacement_required": 409,
28
+ "connector.revocation_pending": 409,
29
+ "dataset.not_found": 404,
30
+ "dataset.version_not_found": 404,
31
+ }
32
+
9
33
  export function toIsoString(value: Date): string {
10
34
  return value.toISOString()
11
35
  }
@@ -58,7 +82,13 @@ export function handleRouteError(
58
82
  set: { status?: number | string }
59
83
  ): {
60
84
  error: string
85
+ code?: SixbErrorCode
61
86
  } {
87
+ if (isSixbError(error)) {
88
+ set.status = HTTP_STATUS_BY_ERROR_CODE[error.code] ?? 500
89
+ return { error: error.message, code: error.code }
90
+ }
91
+
62
92
  if (error instanceof AuthorizationError) {
63
93
  set.status = 403
64
94
  return { error: error.message }
@@ -86,12 +116,10 @@ export function handleRouteError(
86
116
  return { error: error.message }
87
117
  }
88
118
 
89
- // The tail. Core still throws a bare `Error` for "Unknown sync 'x'" and its siblings, so the
90
- // message is all a route has to go on; reading it is a guess that misfires whenever a validation
91
- // message happens to contain one of these words. Every error that gains a class moves above this
92
- // line and the guess covers less.
119
+ // Legacy uncoded errors remain bad requests until their primitive receives a vertical migration.
120
+ // Crucially, wording no longer changes transport semantics.
93
121
  const message = error instanceof Error ? error.message : String(error)
94
- set.status = message.includes("not found") || message.includes("Unknown") ? 404 : 400
122
+ set.status = 400
95
123
  return { error: message }
96
124
  }
97
125
 
package/src/utils/ws.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { AuthorizationContext } from "@sixb/core"
1
+ import type { OntologySource } from "@sixb/core"
2
+ import type { Sixb } from "@sixb/core/internal/request-execution"
2
3
 
3
4
  export function safeSend(target: { send: (message: string) => void }, payload: unknown): void {
4
5
  try {
@@ -14,10 +15,14 @@ export function wsStateKey(ws: object): object {
14
15
  return raw && typeof raw === "object" ? raw : ws
15
16
  }
16
17
 
17
- /** The authorization context attached to a websocket connection; null when unauthenticated/disabled. */
18
- export function wsAuthz(ws: object): AuthorizationContext | null {
19
- const data = (ws as { data?: { authz?: AuthorizationContext | null } }).data
20
- return data?.authz ?? null
18
+ /** The execution SDK attached once when the WebSocket request crosses the auth boundary. */
19
+ export function wsRequestSixb(ws: object): Sixb<readonly OntologySource[]> | null {
20
+ const data = (
21
+ ws as {
22
+ data?: { sixb?: Sixb<readonly OntologySource[]> | null }
23
+ }
24
+ ).data
25
+ return data?.sixb ?? null
21
26
  }
22
27
 
23
28
  function parseJson(text: string): unknown {