@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
package/src/auth/scope.ts CHANGED
@@ -1,35 +1,15 @@
1
- import type { AuthorizationContext, OntologySource, ScopedSixb } from "@sixb/core"
1
+ import type { OntologySource } from "@sixb/core"
2
+ import type { RequestExecutionAuthorization, Sixb } from "@sixb/core/internal/request-execution"
2
3
  import type { AgentRunRecord } from "@sixb/core/storage"
3
4
 
4
5
  /**
5
6
  * Per-request authorization state attached by the server's auth derive.
6
7
  *
7
- * Both fields are null when auth is disabled or the route is public — those
8
- * requests run against the privileged runtime, preserving authenticated-only
9
- * behavior for surfaces that are not grant-enforced yet.
10
- *
11
- * SECURITY — privileged is the silent default. The core runtime treats a
12
- * missing authorization context as fully privileged (workers, syncs, tests
13
- * need that). A scoped principal therefore gains no protection unless the route
14
- * actively routes through `scoped`. Concretely:
15
- *
16
- * - A grant-enforced handler MUST use `scoped` (falling back to the raw
17
- * `sixb` only when `scoped` is null). That now covers writes as well as
18
- * reads: object, link, and telemetry writes enforce `edit:object` and
19
- * `append:telemetry`. Using the raw `sixb` on a path an authenticated
20
- * principal can reach is a silent god-mode bypass — it will not fail to
21
- * compile or to run.
22
- * - Surfaces with no grant family yet (auth admin, raw storage) stay
23
- * authenticated-only by design and use the raw `sixb` deliberately, not by
24
- * omission. Add such a route consciously, and lock it down when its grant
25
- * family lands.
26
- *
27
- * This implicit default is a known V1 trade-off (kept for runtime ergonomics);
28
- * if it proves error-prone, make privileged access explicit at this boundary.
8
+ * Protected domain routes require `sixb`. It is present for authenticated and auth-disabled
9
+ * requests, and absent only for public routes that do not execute protected domain operations.
29
10
  */
30
11
  export interface RequestAuthState {
31
- readonly authz: AuthorizationContext | null
32
- readonly scoped: ScopedSixb<readonly OntologySource[]> | null
12
+ readonly sixb: Sixb<readonly OntologySource[]> | null
33
13
  /** Present for requests proxied through the run-scoped agent API gateway. */
34
14
  readonly agentRun?: AgentRunRecord
35
15
  /** Identifies which kind of active agent execution owns a gateway request. */
@@ -38,16 +18,24 @@ export interface RequestAuthState {
38
18
  | { readonly kind: "workflow"; readonly nodeRunId: string }
39
19
  }
40
20
 
41
- const internalRequestAuthState = new WeakMap<Request, RequestAuthState>()
21
+ export interface InternalRequestAuthState {
22
+ readonly authorization: RequestExecutionAuthorization
23
+ readonly agentRun?: AgentRunRecord
24
+ readonly agentExecution?: RequestAuthState["agentExecution"]
25
+ }
26
+
27
+ const internalRequestAuthState = new WeakMap<Request, InternalRequestAuthState>()
42
28
 
43
29
  export function registerInternalRequestAuthState(
44
30
  request: Request,
45
- authState: RequestAuthState
31
+ authState: InternalRequestAuthState
46
32
  ): void {
47
33
  internalRequestAuthState.set(request, authState)
48
34
  }
49
35
 
50
- export function consumeInternalRequestAuthState(request: Request): RequestAuthState | undefined {
36
+ export function consumeInternalRequestAuthState(
37
+ request: Request
38
+ ): InternalRequestAuthState | undefined {
51
39
  const authState = internalRequestAuthState.get(request)
52
40
  if (authState) {
53
41
  internalRequestAuthState.delete(request)
@@ -63,16 +51,18 @@ export function consumeInternalRequestAuthState(request: Request): RequestAuthSt
63
51
  * point until route registration carries the derived context type.
64
52
  */
65
53
  export function requestAuthState(context: unknown): RequestAuthState {
66
- const {
67
- authz = null,
68
- scoped = null,
69
- agentRun,
70
- agentExecution,
71
- } = context as Partial<RequestAuthState>
54
+ const { sixb = null, agentRun, agentExecution } = context as Partial<RequestAuthState>
72
55
  return {
73
- authz,
74
- scoped,
56
+ sixb,
75
57
  ...(agentRun === undefined ? {} : { agentRun }),
76
58
  ...(agentExecution === undefined ? {} : { agentExecution }),
77
59
  }
78
60
  }
61
+
62
+ export function requireRequestSixb(context: unknown): Sixb<readonly OntologySource[]> {
63
+ const sixb = requestAuthState(context).sixb
64
+ if (!sixb) {
65
+ throw new Error("[SixbServer] Execution scope is not available for this route.")
66
+ }
67
+ return sixb
68
+ }
@@ -1,4 +1,4 @@
1
- import type { OntologySource, Sixb } from "@sixb/core"
1
+ import type { SixbHostView } from "@sixb/core"
2
2
  import {
3
3
  type AuthenticatedAuthSession,
4
4
  createCsrfCookieHeader,
@@ -8,12 +8,12 @@ import {
8
8
  } from "@sixb/core/internal/auth"
9
9
 
10
10
  export function createSessionRenewalCookieHeaders(input: {
11
- readonly sixb: Sixb<readonly OntologySource[]>
11
+ readonly host: SixbHostView
12
12
  readonly request: Request
13
13
  readonly session: AuthenticatedAuthSession
14
14
  readonly csrfToken?: string
15
15
  }): { readonly csrfToken: string; readonly headers: readonly [string, string] } | null {
16
- const cookieOptions = input.sixb.auth.getCookieOptions({
16
+ const cookieOptions = input.host.auth.getCookieOptions({
17
17
  audience: input.session.session.audience,
18
18
  })
19
19
  const sessionValue = getCookie(input.request, cookieOptions.sessionCookieName)
@@ -0,0 +1,110 @@
1
+ import type { SixbHostView } from "@sixb/core"
2
+ import type {
3
+ ConnectorConnectionRunView,
4
+ ConnectorConnectionsRuntime,
5
+ ConnectorConnectionView,
6
+ } from "@sixb/core/internal/connector-connections"
7
+ import {
8
+ getConnectorConnectionsRuntime,
9
+ isOAuthConnectorDefinition,
10
+ } from "@sixb/core/internal/connector-connections"
11
+ import { createSixbError } from "@sixb/core/internal/errors"
12
+ import type { z } from "zod"
13
+ import {
14
+ CONNECTOR_HTTP_ERROR_CODES,
15
+ type ConnectorConnectionRunSchema,
16
+ type ConnectorConnectionSchema,
17
+ type ConnectorHttpErrorCode,
18
+ } from "../schemas/connectors"
19
+ import { handleRouteError, toIsoString } from "../utils/http"
20
+
21
+ export function connectorRouteRuntime(
22
+ host: SixbHostView,
23
+ owner: object,
24
+ connectorId: string
25
+ ): ConnectorConnectionsRuntime {
26
+ const definition = host.definitions.connectors.getById(connectorId)
27
+ if (!definition) {
28
+ throw createSixbError("connector.not_found", "[Sixb] Connector was not found.")
29
+ }
30
+ if (!isOAuthConnectorDefinition(definition)) {
31
+ throw createSixbError(
32
+ "connector.configuration_invalid",
33
+ `[Sixb] Connector '${connectorId}' does not use OAuth authentication.`
34
+ )
35
+ }
36
+ return getConnectorConnectionsRuntime(owner)
37
+ }
38
+
39
+ export function serializeConnectorConnection(
40
+ connection: ConnectorConnectionView
41
+ ): z.infer<typeof ConnectorConnectionSchema> {
42
+ return {
43
+ id: connection.id,
44
+ connectorId: connection.connectorId,
45
+ owner: connection.owner,
46
+ slot: connection.slot,
47
+ account: connection.account,
48
+ status: connection.status,
49
+ }
50
+ }
51
+
52
+ export function serializeConnectorConnectionRun(
53
+ run: ConnectorConnectionRunView
54
+ ): z.infer<typeof ConnectorConnectionRunSchema> {
55
+ const base = {
56
+ id: run.id,
57
+ connectorId: run.connectorId,
58
+ kind: run.kind,
59
+ owner: run.owner,
60
+ slot: run.slot,
61
+ createdAt: toIsoString(run.createdAt),
62
+ updatedAt: toIsoString(run.updatedAt),
63
+ }
64
+ if (run.status === "running") return { ...base, status: "running" }
65
+ if (run.status === "waiting" && run.waitingFor === "provider_authorization") {
66
+ return {
67
+ ...base,
68
+ status: "waiting",
69
+ waitingFor: "provider_authorization",
70
+ expiresAt: toIsoString(run.expiresAt),
71
+ }
72
+ }
73
+ if (run.status === "waiting") {
74
+ return {
75
+ ...base,
76
+ status: "waiting",
77
+ waitingFor: "account_selection",
78
+ accounts: [...run.accounts],
79
+ expiresAt: toIsoString(run.expiresAt),
80
+ }
81
+ }
82
+ if (run.status === "succeeded") {
83
+ return {
84
+ ...base,
85
+ status: "succeeded",
86
+ connections: run.connections.map(serializeConnectorConnection),
87
+ finishedAt: toIsoString(run.finishedAt),
88
+ }
89
+ }
90
+ if (run.status === "failed") {
91
+ return {
92
+ ...base,
93
+ status: "failed",
94
+ error: run.error,
95
+ finishedAt: toIsoString(run.finishedAt),
96
+ }
97
+ }
98
+ return { ...base, status: run.status, finishedAt: toIsoString(run.finishedAt) }
99
+ }
100
+
101
+ export function handleConnectorRouteError(
102
+ error: unknown,
103
+ set: { status?: number | string }
104
+ ): { error: string } | { error: string; code: ConnectorHttpErrorCode } {
105
+ const response = handleRouteError(error, set)
106
+ if (response.code && (CONNECTOR_HTTP_ERROR_CODES as readonly string[]).includes(response.code)) {
107
+ return { error: response.error, code: response.code as ConnectorHttpErrorCode }
108
+ }
109
+ return { error: response.error }
110
+ }
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export type { SixbApiBrowserPolicy, SixbBrowserOrigin } from "./auth/browser-origin"
2
+ export type { SixbAuthExperienceOptions } from "./auth/experience"
2
3
  export { createSixbServer, SixbServer, type SixbServerOptions } from "./server"
@@ -7,13 +7,25 @@ export const OPENAPI_TAGS = {
7
7
  name: "Status",
8
8
  description: "Runtime status",
9
9
  },
10
+ aiAccounting: {
11
+ name: "AI Accounting",
12
+ description: "Project AI token usage, cost analytics, and model-call accounting",
13
+ },
10
14
  ontology: {
11
15
  name: "Ontology",
12
16
  description: "Object type definitions",
13
17
  },
14
18
  connectors: {
15
19
  name: "Connectors",
16
- description: "Connector metadata and webhook routes",
20
+ description: "Connector metadata",
21
+ },
22
+ connectorConnections: {
23
+ name: "Connector Connections",
24
+ description: "Connected external accounts",
25
+ },
26
+ connectorConnectionRuns: {
27
+ name: "Connector Connection Runs",
28
+ description: "Interactive OAuth connection runs",
17
29
  },
18
30
  webhooks: {
19
31
  name: "Webhooks",
@@ -1,9 +1,15 @@
1
- import type { OntologySource, Sixb } from "@sixb/core"
1
+ import type { SixbHostView } from "@sixb/core"
2
2
  import type { Elysia } from "elysia"
3
3
  import { registerActionRunRoutes } from "./routes/action-runs"
4
4
  import { registerActionRoutes } from "./routes/actions"
5
5
  import { registerAgentApiGatewayRoutes } from "./routes/agent-api-gateway"
6
6
  import { registerAgentRoutes } from "./routes/agents"
7
+ import { registerAiAccountingRoutes } from "./routes/ai-accounting"
8
+ import {
9
+ type ConnectorConnectionRouteOptions,
10
+ registerConnectorConnectionRunRoutes,
11
+ } from "./routes/connector-connection-runs"
12
+ import { registerConnectorConnectionRoutes } from "./routes/connector-connections"
7
13
  import { registerConnectorRoutes } from "./routes/connectors"
8
14
  import { registerDatasetRoutes } from "./routes/datasets"
9
15
  import { registerEventRoutes } from "./routes/events"
@@ -22,28 +28,35 @@ import { registerTelemetryRoutes } from "./routes/telemetry"
22
28
  import { registerWebhookRunRoutes } from "./routes/webhook-runs"
23
29
  import { registerWorkflowRoutes } from "./routes/workflows"
24
30
 
25
- export function registerHttpRoutes(app: Elysia, sixb: Sixb<readonly OntologySource[]>) {
26
- registerAgentApiGatewayRoutes(app, sixb)
27
- registerProjectRoutes(app, sixb)
28
- registerStatusRoutes(app, sixb)
29
- registerConnectorRoutes(app, sixb)
30
- registerDatasetRoutes(app, sixb)
31
- registerSyncRoutes(app, sixb)
32
- registerPipelineRoutes(app, sixb)
33
- registerWorkflowRoutes(app, sixb)
34
- registerRuleRoutes(app, sixb)
35
- registerOntologyRoutes(app, sixb)
36
- registerObjectRoutes(app, sixb)
37
- registerActionRoutes(app, sixb)
38
- registerFileRoutes(app, sixb)
39
- registerActionRunRoutes(app, sixb)
40
- registerAgentRoutes(app, sixb)
41
- registerLinkRoutes(app, sixb)
42
- registerTelemetryRoutes(app, sixb)
43
- registerEventRoutes(app, sixb)
44
- registerLogRoutes(app, sixb)
45
- registerProjectionRoutes(app, sixb)
46
- registerWebhookRunRoutes(app, sixb)
31
+ export interface HttpRouteOptions {
32
+ readonly connectorConnections: ConnectorConnectionRouteOptions
33
+ }
34
+
35
+ export function registerHttpRoutes(app: Elysia, host: SixbHostView, options: HttpRouteOptions) {
36
+ registerAgentApiGatewayRoutes(app, host)
37
+ registerAiAccountingRoutes(app, host)
38
+ registerProjectRoutes(app, host)
39
+ registerStatusRoutes(app, host)
40
+ registerConnectorRoutes(app, host)
41
+ registerConnectorConnectionRoutes(app, host)
42
+ registerConnectorConnectionRunRoutes(app, host, options.connectorConnections)
43
+ registerDatasetRoutes(app, host)
44
+ registerSyncRoutes(app, host)
45
+ registerPipelineRoutes(app, host)
46
+ registerWorkflowRoutes(app, host)
47
+ registerRuleRoutes(app, host)
48
+ registerOntologyRoutes(app, host)
49
+ registerObjectRoutes(app, host)
50
+ registerActionRoutes(app, host)
51
+ registerFileRoutes(app, host)
52
+ registerActionRunRoutes(app, host)
53
+ registerAgentRoutes(app, host)
54
+ registerLinkRoutes(app, host)
55
+ registerTelemetryRoutes(app, host)
56
+ registerEventRoutes(app, host)
57
+ registerLogRoutes(app, host)
58
+ registerProjectionRoutes(app, host)
59
+ registerWebhookRunRoutes(app, host)
47
60
 
48
61
  return app
49
62
  }
@@ -1,10 +1,9 @@
1
- import type { OntologySource, Sixb } from "@sixb/core"
2
- import { canViewActionRun } from "@sixb/core/internal/authorization"
1
+ import type { SixbHostView } from "@sixb/core"
3
2
  import type { ActionRunRecord } from "@sixb/core/storage"
4
3
  import type { Elysia } from "elysia"
5
4
  import { z } from "zod"
6
5
  import { bearerSecurityRequirement } from "../auth/access-token-boundary"
7
- import { requestAuthState } from "../auth/scope"
6
+ import { requireRequestSixb } from "../auth/scope"
8
7
  import {
9
8
  createContextualFileContentResponse,
10
9
  fileContentGetResponses,
@@ -63,25 +62,35 @@ function serializeActionRunDetail(
63
62
  ...serializeActionRunSummary(run),
64
63
  params: run.params,
65
64
  writeback: run.writeback
66
- ? {
67
- status: run.writeback.status,
68
- completedAt: toIsoString(run.writeback.completedAt),
69
- ...(run.writeback.result !== undefined ? { result: run.writeback.result } : {}),
70
- error: run.writeback.error,
71
- }
65
+ ? run.writeback.status === "succeeded"
66
+ ? {
67
+ status: "succeeded",
68
+ completedAt: toIsoString(run.writeback.completedAt),
69
+ result: run.writeback.result,
70
+ }
71
+ : {
72
+ status: "failed",
73
+ completedAt: toIsoString(run.writeback.completedAt),
74
+ error: run.writeback.error,
75
+ }
72
76
  : undefined,
73
77
  effects: run.effects
74
- ? {
75
- status: run.effects.status,
76
- completedAt: toIsoString(run.effects.completedAt),
77
- error: run.effects.error,
78
- }
78
+ ? run.effects.status === "succeeded"
79
+ ? {
80
+ status: "succeeded",
81
+ completedAt: toIsoString(run.effects.completedAt),
82
+ }
83
+ : {
84
+ status: "failed",
85
+ completedAt: toIsoString(run.effects.completedAt),
86
+ error: run.effects.error,
87
+ }
79
88
  : undefined,
80
89
  })
81
90
  }
82
91
 
83
92
  async function actionRunFileContentResponse(
84
- sixb: Sixb<readonly OntologySource[]>,
93
+ host: SixbHostView,
85
94
  context: {
86
95
  readonly params: { readonly runId: string }
87
96
  readonly query: unknown
@@ -90,40 +99,36 @@ async function actionRunFileContentResponse(
90
99
  },
91
100
  options: { readonly head?: boolean } = {}
92
101
  ) {
93
- const { authz } = requestAuthState(context)
102
+ const sixb = requireRequestSixb(context)
94
103
 
95
- const storage = sixb.storage.actionRuns
104
+ const storage = host.storage.actionRuns
96
105
  if (!storage) {
97
106
  return unconfiguredStorageResponse(context.set, "Action run storage")
98
107
  }
99
108
 
100
109
  return createContextualFileContentResponse({
101
- blobStorage: sixb.blobStorage,
110
+ blobStorage: host.blobStorage,
102
111
  query: context.query,
103
112
  querySchema: ActionRunFileContentQuerySchema,
104
113
  request: context.request,
105
114
  set: context.set,
106
115
  head: options.head,
107
116
  resolveRoot: async () => {
108
- const run = await storage.getById({ projectId: sixb.id, id: context.params.runId })
109
- if (!run || !canViewActionRun(authz, run)) {
110
- return null
111
- }
112
-
113
- return serializeActionRunDetail(run)
117
+ const run = await sixb.actions.runs.getById(context.params.runId)
118
+ return run ? serializeActionRunDetail(run) : null
114
119
  },
115
120
  })
116
121
  }
117
122
 
118
- export function registerActionRunRoutes(app: Elysia, sixb: Sixb<readonly OntologySource[]>) {
123
+ export function registerActionRunRoutes(app: Elysia, host: SixbHostView) {
119
124
  return app
120
125
  .get(
121
126
  "/api/action-runs",
122
127
  async (context) => {
123
128
  const { query, set } = context
124
- const { authz } = requestAuthState(context)
129
+ const sixb = requireRequestSixb(context)
125
130
  try {
126
- const storage = sixb.storage.actionRuns
131
+ const storage = host.storage.actionRuns
127
132
  if (!storage) {
128
133
  return unconfiguredStorageResponse(set, "Action run storage")
129
134
  }
@@ -131,14 +136,9 @@ export function registerActionRunRoutes(app: Elysia, sixb: Sixb<readonly Ontolog
131
136
  const parsed = ActionRunsQuerySchema.parse(query)
132
137
  const limit = parseOptionalInt(parsed.limit)
133
138
  const offset = parseOptionalInt(parsed.offset)
134
- const actionIds = authz ? [...authz.grants["apply:action"]] : undefined
135
- const objectTypeIds = authz ? [...authz.grants["view:object"]] : undefined
136
- const result = await storage.list({
137
- projectId: sixb.id,
139
+ const result = await sixb.actions.runs.list({
138
140
  actionId: parsed.actionId,
139
- actionIds,
140
141
  objectTypeId: parsed.objectTypeId,
141
- objectTypeIds,
142
142
  primaryId: parsed.primaryId,
143
143
  statuses: parsed.status ? [parsed.status] : undefined,
144
144
  startedAfter: parseDate(parsed.startedAfter),
@@ -176,15 +176,15 @@ export function registerActionRunRoutes(app: Elysia, sixb: Sixb<readonly Ontolog
176
176
  "/api/action-runs/:runId",
177
177
  async (context) => {
178
178
  const { params, set } = context
179
- const { authz } = requestAuthState(context)
179
+ const sixb = requireRequestSixb(context)
180
180
  try {
181
- const storage = sixb.storage.actionRuns
181
+ const storage = host.storage.actionRuns
182
182
  if (!storage) {
183
183
  return unconfiguredStorageResponse(set, "Action run storage")
184
184
  }
185
185
 
186
- const run = await storage.getById({ projectId: sixb.id, id: params.runId })
187
- if (!run || !canViewActionRun(authz, run)) {
186
+ const run = await sixb.actions.runs.getById(params.runId)
187
+ if (!run) {
188
188
  set.status = 404
189
189
  return { error: "Action run not found" }
190
190
  }
@@ -212,7 +212,7 @@ export function registerActionRunRoutes(app: Elysia, sixb: Sixb<readonly Ontolog
212
212
  )
213
213
  .get(
214
214
  "/api/action-runs/:runId/files/content",
215
- (context) => actionRunFileContentResponse(sixb, context),
215
+ (context) => actionRunFileContentResponse(host, context),
216
216
  {
217
217
  params: ActionRunIdParamsSchema,
218
218
  query: ActionRunFileContentQuerySchema,
@@ -228,7 +228,7 @@ export function registerActionRunRoutes(app: Elysia, sixb: Sixb<readonly Ontolog
228
228
  )
229
229
  .head(
230
230
  "/api/action-runs/:runId/files/content",
231
- (context) => actionRunFileContentResponse(sixb, context, { head: true }),
231
+ (context) => actionRunFileContentResponse(host, context, { head: true }),
232
232
  {
233
233
  params: ActionRunIdParamsSchema,
234
234
  query: ActionRunFileContentQuerySchema,
@@ -1,7 +1,7 @@
1
- import type { ActionDefinition, OntologySource, Sixb } from "@sixb/core"
1
+ import type { ActionDefinition, SixbHostView } from "@sixb/core"
2
2
  import type { Elysia } from "elysia"
3
3
  import { bearerSecurityRequirement } from "../auth/access-token-boundary"
4
- import { requestAuthState } from "../auth/scope"
4
+ import { requireRequestSixb } from "../auth/scope"
5
5
  import { OPENAPI_TAGS } from "../openapi/tags"
6
6
  import {
7
7
  ActionCatalogItemSchema,
@@ -38,13 +38,12 @@ function serializeAction(
38
38
  })
39
39
  }
40
40
 
41
- export function registerActionRoutes(app: Elysia, sixb: Sixb<readonly OntologySource[]>) {
41
+ export function registerActionRoutes(app: Elysia, _host: SixbHostView) {
42
42
  return app
43
43
  .get(
44
44
  "/api/actions",
45
45
  async (context) => {
46
- const { scoped } = requestAuthState(context)
47
- const actions = scoped ? scoped.listActions() : sixb.listActions()
46
+ const actions = requireRequestSixb(context).actions.list()
48
47
  return actions.map(serializeAction)
49
48
  },
50
49
  {
@@ -61,10 +60,7 @@ export function registerActionRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
61
60
  "/api/actions/:actionId",
62
61
  async (context) => {
63
62
  const { params, set } = context
64
- const { scoped } = requestAuthState(context)
65
- const action = scoped
66
- ? scoped.getActionById(params.actionId)
67
- : sixb.getActionById(params.actionId)
63
+ const action = requireRequestSixb(context).actions.getById(params.actionId)
68
64
  if (!action) {
69
65
  set.status = 404
70
66
  return { error: "Action not found" }
@@ -87,7 +83,7 @@ export function registerActionRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
87
83
  "/api/actions/:actionId",
88
84
  async (context) => {
89
85
  const { params, body, set } = context
90
- const { scoped } = requestAuthState(context)
86
+ const sixb = requireRequestSixb(context)
91
87
  try {
92
88
  const parsedBody = RequestActionBodySchema.parse(body)
93
89
  const input = {
@@ -96,9 +92,7 @@ export function registerActionRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
96
92
  params: parsedBody.params,
97
93
  runId: parsedBody.runId,
98
94
  }
99
- const result = scoped
100
- ? await scoped.requestAction(input)
101
- : await sixb.actions.request(input)
95
+ const result = await sixb.actions.request(input)
102
96
 
103
97
  set.status = 202
104
98
  return RequestActionResponseSchema.parse(result)