@sixb/server 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/README.md +3 -3
  2. package/dist/auth/application-access.d.ts +2 -2
  3. package/dist/auth/application-access.d.ts.map +1 -1
  4. package/dist/auth/connector-callback-cookie.d.ts +12 -0
  5. package/dist/auth/connector-callback-cookie.d.ts.map +1 -0
  6. package/dist/auth/guard.d.ts +3 -3
  7. package/dist/auth/guard.d.ts.map +1 -1
  8. package/dist/auth/public-routes.d.ts.map +1 -1
  9. package/dist/auth/scope.d.ts +21 -27
  10. package/dist/auth/scope.d.ts.map +1 -1
  11. package/dist/auth/session-cookies.d.ts +2 -2
  12. package/dist/auth/session-cookies.d.ts.map +1 -1
  13. package/dist/connectors/http.d.ts +16 -0
  14. package/dist/connectors/http.d.ts.map +1 -0
  15. package/dist/files/content.d.ts +11 -0
  16. package/dist/files/content.d.ts.map +1 -1
  17. package/dist/index.js +4164 -3541
  18. package/dist/index.js.map +57 -52
  19. package/dist/openapi/tags.d.ts +11 -3
  20. package/dist/openapi/tags.d.ts.map +1 -1
  21. package/dist/registerRoutes.d.ts +6 -2
  22. package/dist/registerRoutes.d.ts.map +1 -1
  23. package/dist/routes/action-runs.d.ts +21 -31
  24. package/dist/routes/action-runs.d.ts.map +1 -1
  25. package/dist/routes/actions.d.ts +9 -8
  26. package/dist/routes/actions.d.ts.map +1 -1
  27. package/dist/routes/agent-api-gateway.d.ts +2 -2
  28. package/dist/routes/agent-api-gateway.d.ts.map +1 -1
  29. package/dist/routes/agents.d.ts +130 -131
  30. package/dist/routes/agents.d.ts.map +1 -1
  31. package/dist/routes/auth.d.ts +90 -90
  32. package/dist/routes/auth.d.ts.map +1 -1
  33. package/dist/routes/connector-connection-runs.d.ts +794 -0
  34. package/dist/routes/connector-connection-runs.d.ts.map +1 -0
  35. package/dist/routes/connector-connections.d.ts +219 -0
  36. package/dist/routes/connector-connections.d.ts.map +1 -0
  37. package/dist/routes/connectors.d.ts +10 -4
  38. package/dist/routes/connectors.d.ts.map +1 -1
  39. package/dist/routes/datasets.d.ts +15 -9
  40. package/dist/routes/datasets.d.ts.map +1 -1
  41. package/dist/routes/events.d.ts +8 -8
  42. package/dist/routes/events.d.ts.map +1 -1
  43. package/dist/routes/files.d.ts +11 -10
  44. package/dist/routes/files.d.ts.map +1 -1
  45. package/dist/routes/links.d.ts +2 -2
  46. package/dist/routes/links.d.ts.map +1 -1
  47. package/dist/routes/logs.d.ts +5 -5
  48. package/dist/routes/logs.d.ts.map +1 -1
  49. package/dist/routes/objects.d.ts +34 -34
  50. package/dist/routes/objects.d.ts.map +1 -1
  51. package/dist/routes/ontology.d.ts +62 -62
  52. package/dist/routes/ontology.d.ts.map +1 -1
  53. package/dist/routes/pipelines.d.ts +28 -34
  54. package/dist/routes/pipelines.d.ts.map +1 -1
  55. package/dist/routes/project.d.ts +2 -2
  56. package/dist/routes/project.d.ts.map +1 -1
  57. package/dist/routes/projections.d.ts +131 -83
  58. package/dist/routes/projections.d.ts.map +1 -1
  59. package/dist/routes/rules.d.ts +6 -6
  60. package/dist/routes/rules.d.ts.map +1 -1
  61. package/dist/routes/status.d.ts +2 -2
  62. package/dist/routes/status.d.ts.map +1 -1
  63. package/dist/routes/syncs.d.ts +27 -30
  64. package/dist/routes/syncs.d.ts.map +1 -1
  65. package/dist/routes/telemetry.d.ts +2 -2
  66. package/dist/routes/telemetry.d.ts.map +1 -1
  67. package/dist/routes/webhook-runs.d.ts +9 -9
  68. package/dist/routes/webhook-runs.d.ts.map +1 -1
  69. package/dist/routes/webhooks.d.ts +2 -2
  70. package/dist/routes/webhooks.d.ts.map +1 -1
  71. package/dist/routes/workflows.d.ts +132 -107
  72. package/dist/routes/workflows.d.ts.map +1 -1
  73. package/dist/routes/ws/agents.d.ts +11 -5
  74. package/dist/routes/ws/agents.d.ts.map +1 -1
  75. package/dist/routes/ws/events.d.ts +8 -8
  76. package/dist/routes/ws/events.d.ts.map +1 -1
  77. package/dist/routes/ws/log-subscription-hub.d.ts +6 -3
  78. package/dist/routes/ws/log-subscription-hub.d.ts.map +1 -1
  79. package/dist/routes/ws/logs.d.ts +10 -10
  80. package/dist/routes/ws/logs.d.ts.map +1 -1
  81. package/dist/schemas/actions.d.ts +97 -202
  82. package/dist/schemas/actions.d.ts.map +1 -1
  83. package/dist/schemas/agents.d.ts +443 -440
  84. package/dist/schemas/agents.d.ts.map +1 -1
  85. package/dist/schemas/ai-usage.d.ts +34 -0
  86. package/dist/schemas/ai-usage.d.ts.map +1 -0
  87. package/dist/schemas/auth.d.ts +168 -168
  88. package/dist/schemas/common.d.ts +37 -0
  89. package/dist/schemas/common.d.ts.map +1 -1
  90. package/dist/schemas/connectors.d.ts +713 -2
  91. package/dist/schemas/connectors.d.ts.map +1 -1
  92. package/dist/schemas/datasets.d.ts +29 -23
  93. package/dist/schemas/datasets.d.ts.map +1 -1
  94. package/dist/schemas/event-payloads.d.ts +6 -6
  95. package/dist/schemas/events.d.ts +34 -34
  96. package/dist/schemas/logs.d.ts +22 -22
  97. package/dist/schemas/objects.d.ts +10 -10
  98. package/dist/schemas/ontology.d.ts +174 -174
  99. package/dist/schemas/pipelines.d.ts +131 -190
  100. package/dist/schemas/pipelines.d.ts.map +1 -1
  101. package/dist/schemas/projections.d.ts +918 -563
  102. package/dist/schemas/projections.d.ts.map +1 -1
  103. package/dist/schemas/rules.d.ts +6 -6
  104. package/dist/schemas/status.d.ts +2 -2
  105. package/dist/schemas/syncs.d.ts +88 -124
  106. package/dist/schemas/syncs.d.ts.map +1 -1
  107. package/dist/schemas/webhook-runs.d.ts +41 -41
  108. package/dist/schemas/webhook-runs.d.ts.map +1 -1
  109. package/dist/schemas/workflows.d.ts +792 -406
  110. package/dist/schemas/workflows.d.ts.map +1 -1
  111. package/dist/server.d.ts +6 -6
  112. package/dist/server.d.ts.map +1 -1
  113. package/dist/utils/http.d.ts +2 -0
  114. package/dist/utils/http.d.ts.map +1 -1
  115. package/dist/utils/ws.d.ts +4 -3
  116. package/dist/utils/ws.d.ts.map +1 -1
  117. package/package.json +8 -5
  118. package/src/auth/access-token-boundary.ts +4 -4
  119. package/src/auth/application-access.ts +8 -9
  120. package/src/auth/connector-callback-cookie.ts +95 -0
  121. package/src/auth/guard.ts +11 -11
  122. package/src/auth/public-routes.ts +13 -0
  123. package/src/auth/scope.ts +34 -30
  124. package/src/auth/session-cookies.ts +3 -3
  125. package/src/connectors/http.ts +110 -0
  126. package/src/files/content.ts +11 -0
  127. package/src/openapi/tags.ts +9 -1
  128. package/src/registerRoutes.ts +34 -23
  129. package/src/routes/action-runs.ts +49 -42
  130. package/src/routes/actions.ts +7 -13
  131. package/src/routes/agent-api-gateway.ts +87 -42
  132. package/src/routes/agents.ts +89 -200
  133. package/src/routes/auth.ts +87 -91
  134. package/src/routes/connector-connection-runs.ts +346 -0
  135. package/src/routes/connector-connections.ts +135 -0
  136. package/src/routes/connectors.ts +24 -12
  137. package/src/routes/datasets.ts +55 -54
  138. package/src/routes/events.ts +5 -5
  139. package/src/routes/files.ts +24 -31
  140. package/src/routes/links.ts +32 -35
  141. package/src/routes/logs.ts +6 -11
  142. package/src/routes/objects.ts +51 -114
  143. package/src/routes/ontology.ts +27 -38
  144. package/src/routes/pipelines.ts +28 -62
  145. package/src/routes/project.ts +3 -3
  146. package/src/routes/projections.ts +26 -38
  147. package/src/routes/rules.ts +11 -25
  148. package/src/routes/status.ts +5 -5
  149. package/src/routes/syncs.ts +19 -45
  150. package/src/routes/telemetry.ts +18 -29
  151. package/src/routes/webhook-runs.ts +5 -5
  152. package/src/routes/webhooks.ts +259 -341
  153. package/src/routes/workflows.ts +260 -259
  154. package/src/routes/ws/agents.ts +196 -66
  155. package/src/routes/ws/events.ts +11 -10
  156. package/src/routes/ws/log-subscription-hub.ts +6 -12
  157. package/src/routes/ws/logs.ts +13 -5
  158. package/src/schemas/actions.ts +58 -25
  159. package/src/schemas/agents.ts +19 -14
  160. package/src/schemas/ai-usage.ts +16 -0
  161. package/src/schemas/common.ts +24 -0
  162. package/src/schemas/connectors.ts +164 -0
  163. package/src/schemas/datasets.ts +3 -2
  164. package/src/schemas/pipelines.ts +24 -40
  165. package/src/schemas/projections.ts +17 -3
  166. package/src/schemas/syncs.ts +16 -10
  167. package/src/schemas/webhook-runs.ts +10 -5
  168. package/src/schemas/workflows.ts +42 -25
  169. package/src/server.ts +65 -26
  170. package/src/utils/http.ts +34 -6
  171. package/src/utils/ws.ts +10 -5
@@ -1,4 +1,18 @@
1
+ import {
2
+ type SixbFailure,
3
+ WORKFLOW_RUN_FAILURE_CODES,
4
+ type WorkflowRunFailureCode,
5
+ } from "@sixb/core/storage"
1
6
  import { z } from "zod"
7
+ import { AgentRunFailureSchema } from "./agents"
8
+ import { AiUsageSummarySchema } from "./ai-usage"
9
+ import { JsonValueSchema, sixbFailureSchema } from "./common"
10
+
11
+ export const WorkflowIOSnapshotSchema = z.record(JsonValueSchema)
12
+
13
+ const WorkflowRunFailureSchema: z.ZodType<SixbFailure<WorkflowRunFailureCode>> = sixbFailureSchema(
14
+ WORKFLOW_RUN_FAILURE_CODES
15
+ )
2
16
 
3
17
  export const WorkflowParamsSchema = z.object({
4
18
  workflowId: z.string().min(1),
@@ -55,7 +69,7 @@ export const WorkflowInterventionsQuerySchema = z.object({
55
69
 
56
70
  export const RequestWorkflowRunBodySchema = z
57
71
  .object({
58
- input: z.record(z.unknown()).optional(),
72
+ input: WorkflowIOSnapshotSchema.optional(),
59
73
  })
60
74
  .default({})
61
75
 
@@ -67,7 +81,7 @@ export const WorkflowInterventionActorSchema = z.object({
67
81
  export const CancelWorkflowRunBodySchema = z.object({}).default({})
68
82
 
69
83
  export const SubmitWorkflowInterventionBodySchema = z.object({
70
- response: z.record(z.unknown()),
84
+ response: WorkflowIOSnapshotSchema,
71
85
  })
72
86
 
73
87
  export const CancelWorkflowInterventionBodySchema = z.object({}).default({})
@@ -82,22 +96,22 @@ const WorkflowNodeSchema = z.union([
82
96
  type: z.literal("step"),
83
97
  id: z.string(),
84
98
  key: z.string(),
85
- input: z.record(z.unknown()),
86
- output: z.record(z.unknown()),
99
+ input: WorkflowIOSnapshotSchema,
100
+ output: WorkflowIOSnapshotSchema,
87
101
  }),
88
102
  z.object({
89
103
  type: z.literal("action"),
90
104
  id: z.string(),
91
105
  key: z.string(),
92
106
  objectTypeId: z.string().optional(),
93
- params: z.record(z.unknown()),
107
+ params: WorkflowIOSnapshotSchema,
94
108
  }),
95
109
  z.object({
96
110
  type: z.literal("intervention"),
97
111
  id: z.string(),
98
112
  key: z.string(),
99
- input: z.record(z.unknown()),
100
- response: z.record(z.unknown()),
113
+ input: WorkflowIOSnapshotSchema,
114
+ response: WorkflowIOSnapshotSchema,
101
115
  description: z.string().optional(),
102
116
  }),
103
117
  z.object({
@@ -105,31 +119,35 @@ const WorkflowNodeSchema = z.union([
105
119
  id: z.string(),
106
120
  key: z.string(),
107
121
  agentId: z.string(),
108
- input: z.record(z.unknown()),
109
- output: z.record(z.unknown()),
122
+ input: WorkflowIOSnapshotSchema,
123
+ output: WorkflowIOSnapshotSchema,
110
124
  }),
111
125
  ])
112
126
 
113
- export const WorkflowRunSchema = z.object({
127
+ export const WorkflowRunSummarySchema = z.object({
114
128
  id: z.string(),
115
129
  projectId: z.string(),
116
130
  workflowId: z.string(),
117
131
  status: WorkflowRunStatusSchema,
118
- input: z.record(z.unknown()),
119
132
  queuedAt: z.string().optional(),
120
133
  startedAt: z.string(),
121
134
  finishedAt: z.string().optional(),
122
- error: z.string().optional(),
135
+ error: WorkflowRunFailureSchema.optional(),
123
136
  requestedBy: WorkflowInterventionActorSchema,
124
137
  })
125
138
 
139
+ export const WorkflowRunDetailSchema = WorkflowRunSummarySchema.extend({
140
+ input: WorkflowIOSnapshotSchema,
141
+ output: WorkflowIOSnapshotSchema.optional(),
142
+ })
143
+
126
144
  export const WorkflowAgentNodeExecutionSummarySchema = z.object({
127
145
  agentId: z.string(),
128
146
  status: z.enum(["queued", "running", "succeeded", "failed", "cancelled"]),
129
147
  attempt: z.number().int().nonnegative(),
130
148
  modelId: z.string().optional(),
131
149
  finishReason: z.string().optional(),
132
- usage: z.record(z.unknown()).optional(),
150
+ usage: AiUsageSummarySchema.optional(),
133
151
  startedAt: z.string().optional(),
134
152
  completedAt: z.string().optional(),
135
153
  })
@@ -137,10 +155,9 @@ export const WorkflowAgentNodeExecutionSummarySchema = z.object({
137
155
  export const WorkflowAgentNodeExecutionSchema = WorkflowAgentNodeExecutionSummarySchema.extend({
138
156
  nodeRunId: z.string(),
139
157
  prompt: z.string(),
140
- executionPrincipal: WorkflowInterventionActorSchema.optional(),
141
158
  trace: z.array(z.unknown()).optional(),
142
159
  diagnostics: z.array(z.unknown()).optional(),
143
- error: z.string().optional(),
160
+ error: AgentRunFailureSchema.optional(),
144
161
  createdAt: z.string(),
145
162
  })
146
163
 
@@ -154,11 +171,11 @@ export const WorkflowNodeRunSchema = z.object({
154
171
  nodeId: z.string(),
155
172
  nodeKey: z.string(),
156
173
  status: z.enum(["running", "waiting", "succeeded", "failed", "cancelled"]),
157
- input: z.record(z.unknown()),
174
+ input: WorkflowIOSnapshotSchema,
158
175
  startedAt: z.string(),
159
176
  finishedAt: z.string().optional(),
160
- output: z.record(z.unknown()).optional(),
161
- error: z.string().optional(),
177
+ output: WorkflowIOSnapshotSchema.optional(),
178
+ error: WorkflowRunFailureSchema.optional(),
162
179
  agentExecution: WorkflowAgentNodeExecutionSummarySchema.optional(),
163
180
  })
164
181
 
@@ -172,14 +189,14 @@ export const WorkflowInterventionSchema = z.object({
172
189
  nodeId: z.string(),
173
190
  nodeKey: z.string(),
174
191
  interventionId: z.string(),
175
- input: z.record(z.unknown()),
176
- defaultResponse: z.record(z.unknown()),
192
+ input: WorkflowIOSnapshotSchema,
193
+ defaultResponse: WorkflowIOSnapshotSchema,
177
194
  status: WorkflowInterventionStatusSchema,
178
195
  requestedAt: z.string(),
179
196
  expiresAt: z.string().optional(),
180
197
  submittedAt: z.string().optional(),
181
198
  submittedBy: WorkflowInterventionActorSchema.optional(),
182
- response: z.record(z.unknown()).optional(),
199
+ response: WorkflowIOSnapshotSchema.optional(),
183
200
  cancelledAt: z.string().optional(),
184
201
  cancelledBy: WorkflowInterventionActorSchema.optional(),
185
202
  expiredAt: z.string().optional(),
@@ -187,20 +204,20 @@ export const WorkflowInterventionSchema = z.object({
187
204
 
188
205
  export const WorkflowSchema = z.object({
189
206
  id: z.string(),
190
- input: z.record(z.unknown()),
207
+ input: WorkflowIOSnapshotSchema,
191
208
  triggers: z.array(WorkflowTriggerSchema),
192
209
  nodes: z.array(WorkflowNodeSchema),
193
- latestRun: WorkflowRunSchema.nullable(),
210
+ latestRun: WorkflowRunSummarySchema.nullable(),
194
211
  })
195
212
 
196
213
  export const WorkflowRunListResponseSchema = z.object({
197
- runs: z.array(WorkflowRunSchema),
214
+ runs: z.array(WorkflowRunSummarySchema),
198
215
  hasMore: z.boolean(),
199
216
  total: z.number(),
200
217
  })
201
218
 
202
219
  export const WorkflowRunDetailResponseSchema = z.object({
203
- run: WorkflowRunSchema,
220
+ run: WorkflowRunDetailSchema,
204
221
  nodes: z.array(WorkflowNodeRunSchema),
205
222
  })
206
223
 
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"
@@ -43,9 +44,9 @@ import { jsonValueOpenApiOverride } from "./schemas/common"
43
44
  import { ObjectQueryOpenApiSchemas } from "./schemas/objects"
44
45
 
45
46
  export interface SixbServerOptions {
46
- sixb: Sixb<readonly OntologySource[]>
47
+ host: SixbHostView
47
48
  port?: number
48
- host?: string
49
+ hostname?: string
49
50
  quiet?: boolean
50
51
  browser: SixbApiBrowserPolicy
51
52
  }
@@ -55,9 +56,9 @@ export function createSixbServer(options: SixbServerOptions): SixbServer {
55
56
  }
56
57
 
57
58
  export class SixbServer {
58
- private readonly sixb: Sixb<readonly OntologySource[]>
59
+ private readonly hostRuntime: SixbHostView
59
60
  private readonly port: number
60
- private readonly host: string
61
+ private readonly hostname: string
61
62
  private readonly quiet: boolean
62
63
  private readonly apiBrowserPolicy: ResolvedSixbApiBrowserPolicy
63
64
  private readonly authContextResolver: ResolveRequestAuthContext
@@ -67,9 +68,9 @@ export class SixbServer {
67
68
  private maintenance: OntologyMaintenanceHandle | null = null
68
69
 
69
70
  constructor(options: SixbServerOptions) {
70
- this.sixb = options.sixb
71
+ this.hostRuntime = options.host
71
72
  this.port = options.port ?? 3000
72
- this.host = options.host ?? "0.0.0.0"
73
+ this.hostname = options.hostname ?? "0.0.0.0"
73
74
  this.quiet = options.quiet ?? false
74
75
  this.apiBrowserPolicy = resolveApiBrowserPolicy(options.browser)
75
76
  this.authContextResolver = createApiBrowserAuthContextResolver(this.apiBrowserPolicy)
@@ -78,8 +79,8 @@ export class SixbServer {
78
79
  )
79
80
  }
80
81
 
81
- getSixb(): Sixb<readonly OntologySource[]> {
82
- return this.sixb
82
+ getHost(): SixbHostView {
83
+ return this.hostRuntime
83
84
  }
84
85
 
85
86
  getPort(): number {
@@ -121,13 +122,13 @@ export class SixbServer {
121
122
  throw new Error("[SixbServer] Server is already running.")
122
123
  }
123
124
 
124
- const maintenance = await this.sixb.startOntologyMaintenance()
125
+ const maintenance = await this.hostRuntime.startOntologyMaintenance()
125
126
  this.maintenance = maintenance
126
127
 
127
128
  try {
128
129
  this.app = createSixbApi(this)
129
130
  this.bunServer = startApiServer(this.app, {
130
- host: this.host,
131
+ host: this.hostname,
131
132
  port: this.port,
132
133
  })
133
134
  } catch (error) {
@@ -136,11 +137,11 @@ export class SixbServer {
136
137
  this.maintenance = null
137
138
  await maintenance.stop()
138
139
  const message = error instanceof Error ? error.message : String(error)
139
- throw new Error(`[SixbServer] Failed to listen on ${this.host}:${this.port}: ${message}`)
140
+ throw new Error(`[SixbServer] Failed to listen on ${this.hostname}:${this.port}: ${message}`)
140
141
  }
141
142
 
142
143
  if (!this.quiet) {
143
- const base = `http://${this.host}:${this.port}`
144
+ const base = `http://${this.hostname}:${this.port}`
144
145
  console.log(`Sixb server running at ${base}`)
145
146
  console.log(`OpenAPI docs at ${base}/docs`)
146
147
  }
@@ -164,9 +165,9 @@ export class SixbServer {
164
165
  }
165
166
 
166
167
  export function createSixbApi(server: SixbServer) {
167
- const sixb = server.getSixb()
168
+ const host = server.getHost()
168
169
  const guard = new ServerAuthGuard({
169
- sixb,
170
+ host,
170
171
  resolveAuthContext: (request) => server.resolveAuthContext(request),
171
172
  })
172
173
  guard.assertCanServeHttp({ production: process.env.NODE_ENV === "production" })
@@ -196,23 +197,49 @@ export function createSixbApi(server: SixbServer) {
196
197
  })
197
198
  )
198
199
 
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).
200
+ // Resolve authentication and bind one execution SDK at the request boundary. Protected routes
201
+ // never choose between a principal SDK and the ambient runtime themselves.
202
202
  app
203
203
  .derive(async ({ request }) => {
204
204
  const internalAuthState = consumeInternalRequestAuthState(request)
205
205
  if (internalAuthState) {
206
- return { auth: { kind: "allow" as const, session: null }, ...internalAuthState }
206
+ const { authorization, ...agentState } = internalAuthState
207
+ return {
208
+ auth: { kind: "allow" as const, session: null },
209
+ ...agentState,
210
+ sixb: bindRequestExecution(host, {
211
+ request,
212
+ authorization,
213
+ }),
214
+ }
207
215
  }
208
216
 
209
217
  const auth = await guard.resolve(request)
210
218
  if (auth.kind === "deny" || !auth.session?.authenticated) {
211
- return { auth, authz: null, scoped: null }
219
+ return {
220
+ auth,
221
+ sixb:
222
+ auth.kind === "allow" && !guard.isAuthEnabled()
223
+ ? bindRequestExecution(host, {
224
+ request,
225
+ authorization: { type: "disabled" },
226
+ })
227
+ : null,
228
+ }
212
229
  }
213
230
 
214
- const authz = sixb.auth.contextFromSession(auth.session)
215
- return { auth, authz, scoped: sixb.as(authz) }
231
+ const authz = host.auth.contextFromSession(auth.session)
232
+ const credential =
233
+ auth.session.credentialSource === "session"
234
+ ? { type: "session" as const, id: auth.session.session.id }
235
+ : { type: "accessToken" as const, id: auth.session.accessToken.id }
236
+ return {
237
+ auth,
238
+ sixb: bindRequestExecution(host, {
239
+ request,
240
+ authorization: { type: "principal", context: authz, credential },
241
+ }),
242
+ }
216
243
  })
217
244
  .onBeforeHandle(({ auth }) => (auth.kind === "deny" ? auth.response : undefined))
218
245
  .mapResponse(({ auth, request, set }) => {
@@ -226,7 +253,7 @@ export function createSixbApi(server: SixbServer) {
226
253
  }
227
254
 
228
255
  const renewal = createSessionRenewalCookieHeaders({
229
- sixb,
256
+ host: host,
230
257
  request,
231
258
  session: auth.session,
232
259
  })
@@ -271,7 +298,7 @@ export function createSixbApi(server: SixbServer) {
271
298
  })
272
299
  )
273
300
 
274
- registerAuthRoutes(app, sixb, {
301
+ registerAuthRoutes(app, host, {
275
302
  resolveAuthContext: (request) => server.resolveAuthContext(request),
276
303
  resolveAuthRedirectContext: (request, input) =>
277
304
  server.resolveAuthRedirectContext(request, input),
@@ -280,8 +307,20 @@ export function createSixbApi(server: SixbServer) {
280
307
  resolveInvitationRedirectContext: (request, input) =>
281
308
  server.resolveInvitationRedirectContext(request, input),
282
309
  })
283
- registerHttpRoutes(app, sixb)
284
- registerWebhookRoutes(app, sixb)
310
+ registerHttpRoutes(app, host, {
311
+ connectorConnections: {
312
+ resolveReturnTo: (request, returnTo) => {
313
+ const authContext = server.resolveAuthContext(request)
314
+ return server.resolveAuthRedirectContext(request, {
315
+ audience: authContext.audience,
316
+ returnTo,
317
+ }).returnTo
318
+ },
319
+ resolveCallbackUrl: (request) =>
320
+ new URL("/auth/connectors/callback", server.resolveAuthRequestOrigin(request)).toString(),
321
+ },
322
+ })
323
+ registerWebhookRoutes(app, host)
285
324
  registerWebSocketRoutes(app, server)
286
325
 
287
326
  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 {