@sixb/server 0.1.11 → 0.1.13

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 (104) hide show
  1. package/README.md +5 -4
  2. package/dist/auth/access-token-boundary.d.ts +13 -9
  3. package/dist/auth/access-token-boundary.d.ts.map +1 -1
  4. package/dist/auth/client-address.d.ts +12 -0
  5. package/dist/auth/client-address.d.ts.map +1 -0
  6. package/dist/auth/guard.d.ts.map +1 -1
  7. package/dist/auth/public-routes.d.ts +5 -0
  8. package/dist/auth/public-routes.d.ts.map +1 -1
  9. package/dist/auth/rate-limit.d.ts +15 -0
  10. package/dist/auth/rate-limit.d.ts.map +1 -0
  11. package/dist/auth/scope.d.ts +8 -3
  12. package/dist/auth/scope.d.ts.map +1 -1
  13. package/dist/auth/shared-access.d.ts.map +1 -1
  14. package/dist/index.js +723 -480
  15. package/dist/index.js.map +43 -41
  16. package/dist/openapi/security.d.ts +34 -10
  17. package/dist/openapi/security.d.ts.map +1 -1
  18. package/dist/routes/agents.d.ts +121 -34
  19. package/dist/routes/agents.d.ts.map +1 -1
  20. package/dist/routes/ai-accounting.d.ts.map +1 -1
  21. package/dist/routes/auth.d.ts +64 -17
  22. package/dist/routes/auth.d.ts.map +1 -1
  23. package/dist/routes/connectors.d.ts.map +1 -1
  24. package/dist/routes/datasets.d.ts +8 -8
  25. package/dist/routes/events.d.ts +0 -4
  26. package/dist/routes/events.d.ts.map +1 -1
  27. package/dist/routes/files.d.ts +15 -2
  28. package/dist/routes/files.d.ts.map +1 -1
  29. package/dist/routes/models.d.ts +7 -7
  30. package/dist/routes/objects.d.ts +16 -5
  31. package/dist/routes/objects.d.ts.map +1 -1
  32. package/dist/routes/ontology.d.ts +37 -13
  33. package/dist/routes/ontology.d.ts.map +1 -1
  34. package/dist/routes/shared-access.d.ts.map +1 -1
  35. package/dist/routes/syncs.d.ts +5 -5
  36. package/dist/routes/workflows.d.ts +36 -36
  37. package/dist/routes/workflows.d.ts.map +1 -1
  38. package/dist/routes/ws/agents.d.ts +2 -3
  39. package/dist/routes/ws/agents.d.ts.map +1 -1
  40. package/dist/schemas/agents.d.ts +205 -100
  41. package/dist/schemas/agents.d.ts.map +1 -1
  42. package/dist/schemas/ai-accounting.d.ts +692 -104
  43. package/dist/schemas/ai-accounting.d.ts.map +1 -1
  44. package/dist/schemas/ai-usage.d.ts +2 -2
  45. package/dist/schemas/auth.d.ts +241 -85
  46. package/dist/schemas/auth.d.ts.map +1 -1
  47. package/dist/schemas/common.d.ts +26 -0
  48. package/dist/schemas/common.d.ts.map +1 -1
  49. package/dist/schemas/datasets.d.ts +22 -22
  50. package/dist/schemas/events.d.ts +74 -44
  51. package/dist/schemas/events.d.ts.map +1 -1
  52. package/dist/schemas/models.d.ts +42 -42
  53. package/dist/schemas/objects.d.ts +8 -0
  54. package/dist/schemas/objects.d.ts.map +1 -1
  55. package/dist/schemas/ontology.d.ts +259 -49
  56. package/dist/schemas/ontology.d.ts.map +1 -1
  57. package/dist/schemas/syncs.d.ts +12 -12
  58. package/dist/schemas/workflows.d.ts +230 -240
  59. package/dist/schemas/workflows.d.ts.map +1 -1
  60. package/dist/server.d.ts +6 -0
  61. package/dist/server.d.ts.map +1 -1
  62. package/dist/utils/ws.d.ts +1 -2
  63. package/dist/utils/ws.d.ts.map +1 -1
  64. package/package.json +5 -5
  65. package/src/auth/access-token-boundary.ts +31 -30
  66. package/src/auth/client-address.ts +67 -0
  67. package/src/auth/guard.ts +13 -4
  68. package/src/auth/public-routes.ts +9 -2
  69. package/src/auth/rate-limit.ts +43 -0
  70. package/src/auth/scope.ts +13 -3
  71. package/src/auth/shared-access.ts +0 -3
  72. package/src/openapi/security.ts +37 -17
  73. package/src/routes/action-runs.ts +5 -5
  74. package/src/routes/actions.ts +4 -4
  75. package/src/routes/agents.ts +56 -14
  76. package/src/routes/ai-accounting.ts +11 -10
  77. package/src/routes/auth.ts +331 -432
  78. package/src/routes/connector-connection-runs.ts +5 -5
  79. package/src/routes/connector-connections.ts +3 -3
  80. package/src/routes/connectors.ts +2 -2
  81. package/src/routes/events.ts +2 -2
  82. package/src/routes/files.ts +30 -15
  83. package/src/routes/links.ts +3 -3
  84. package/src/routes/logs.ts +2 -2
  85. package/src/routes/objects.ts +58 -14
  86. package/src/routes/ontology.ts +42 -14
  87. package/src/routes/pipelines.ts +2 -2
  88. package/src/routes/project.ts +2 -2
  89. package/src/routes/share-grants.ts +4 -4
  90. package/src/routes/shared-access.ts +3 -2
  91. package/src/routes/syncs.ts +2 -2
  92. package/src/routes/telemetry.ts +5 -5
  93. package/src/routes/workflows.ts +18 -19
  94. package/src/routes/ws/agents.ts +4 -5
  95. package/src/schemas/agents.ts +9 -0
  96. package/src/schemas/ai-accounting.ts +19 -1
  97. package/src/schemas/auth.ts +27 -8
  98. package/src/schemas/common.ts +11 -0
  99. package/src/schemas/events.ts +35 -7
  100. package/src/schemas/objects.ts +18 -6
  101. package/src/schemas/ontology.ts +31 -7
  102. package/src/schemas/workflows.ts +4 -9
  103. package/src/server.ts +35 -5
  104. package/src/utils/ws.ts +2 -3
@@ -20,12 +20,26 @@ export const PropertyDefinitionSchema = z.object({
20
20
  text: z.boolean().optional(),
21
21
  exact: z.boolean().optional(),
22
22
  facet: z.boolean().optional(),
23
- vector: z.boolean().optional(),
24
23
  weight: z.number().optional(),
25
24
  })
26
25
  .optional(),
27
26
  })
28
27
 
28
+ export const PropertyQueryCapabilitiesSchema = z
29
+ .object({
30
+ operators: z.array(z.enum(["eq", "neq", "lt", "lte", "gt", "gte", "in", "exists", "contains"])),
31
+ sortable: z.boolean(),
32
+ facet: z.boolean(),
33
+ text: z.boolean(),
34
+ })
35
+ .describe(
36
+ "What object queries accept for this property, resolved from its schema and query metadata."
37
+ )
38
+
39
+ export const ObjectPropertyDefinitionSchema = PropertyDefinitionSchema.extend({
40
+ capabilities: PropertyQueryCapabilitiesSchema,
41
+ })
42
+
29
43
  export const LinkDefinitionSchema = z.object({
30
44
  id: z.string(),
31
45
  name: z.string(),
@@ -58,17 +72,27 @@ export const ObjectTypeSchema = z.object({
58
72
  description: z.string().optional(),
59
73
  extends: z.string().optional(),
60
74
  implements: z.array(z.string()).optional(),
61
- properties: z.array(PropertyDefinitionSchema),
75
+ properties: z.array(ObjectPropertyDefinitionSchema),
62
76
  search: z
63
77
  .object({
64
78
  title: z.string().optional(),
65
79
  defaultText: z.array(z.string()).optional(),
66
80
  exact: z.array(z.string()).optional(),
67
- vector: z
68
- .object({
69
- property: z.string(),
70
- source: z.array(z.string()),
71
- })
81
+ vectors: z
82
+ .record(
83
+ z.string(),
84
+ z.object({
85
+ source: z.array(z.string()),
86
+ model: z.object({
87
+ providerId: z.string(),
88
+ modelId: z.string(),
89
+ dimensions: z.number().int().positive(),
90
+ representation: z
91
+ .object({ name: z.string(), version: z.string().optional() })
92
+ .optional(),
93
+ }),
94
+ })
95
+ )
72
96
  .optional(),
73
97
  })
74
98
  .optional(),
@@ -7,7 +7,7 @@ import { z } from "zod"
7
7
  import { AgentMessagePartSchema, AgentRunFailureSchema } from "./agents"
8
8
  import { AiCostSummarySchema } from "./ai-accounting"
9
9
  import { AiUsageSummarySchema } from "./ai-usage"
10
- import { JsonValueSchema, sixbFailureSchema } from "./common"
10
+ import { JsonValueSchema, PrincipalSchema, sixbFailureSchema } from "./common"
11
11
 
12
12
  export const WorkflowIOSnapshotSchema = z.record(JsonValueSchema)
13
13
 
@@ -74,11 +74,6 @@ export const RequestWorkflowRunBodySchema = z
74
74
  })
75
75
  .default({})
76
76
 
77
- export const WorkflowInterventionActorSchema = z.object({
78
- principalType: z.enum(["user", "serviceAccount", "system"]),
79
- principalId: z.string().min(1),
80
- })
81
-
82
77
  export const CancelWorkflowRunBodySchema = z.object({}).default({})
83
78
 
84
79
  export const SubmitWorkflowInterventionBodySchema = z.object({
@@ -133,7 +128,7 @@ export const WorkflowRunSummarySchema = z.object({
133
128
  startedAt: z.string(),
134
129
  finishedAt: z.string().optional(),
135
130
  error: WorkflowRunFailureSchema.optional(),
136
- requestedBy: WorkflowInterventionActorSchema,
131
+ requestedBy: PrincipalSchema,
137
132
  })
138
133
 
139
134
  export const WorkflowRunDetailSchema = WorkflowRunSummarySchema.extend({
@@ -198,10 +193,10 @@ export const WorkflowInterventionSchema = z.object({
198
193
  requestedAt: z.string(),
199
194
  expiresAt: z.string().optional(),
200
195
  submittedAt: z.string().optional(),
201
- submittedBy: WorkflowInterventionActorSchema.optional(),
196
+ submittedBy: PrincipalSchema.optional(),
202
197
  response: WorkflowIOSnapshotSchema.optional(),
203
198
  cancelledAt: z.string().optional(),
204
- cancelledBy: WorkflowInterventionActorSchema.optional(),
199
+ cancelledBy: PrincipalSchema.optional(),
205
200
  expiredAt: z.string().optional(),
206
201
  })
207
202
 
package/src/server.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { cors } from "@elysiajs/cors"
2
2
  import { openapi } from "@elysiajs/openapi"
3
3
  import type { OntologyMaintenanceHandle, SixbHostView } from "@sixb/core"
4
- import { CSRF_HEADER_NAME } from "@sixb/core/internal/auth"
4
+ import { CSRF_HEADER_NAME, setRequestClientAddress } from "@sixb/core/internal/auth"
5
5
  import { bindRequestExecution } from "@sixb/core/internal/request-execution"
6
+ import type { Server } from "bun"
6
7
  import { Elysia } from "elysia"
7
8
  import { websocket as elysiaWebSocket } from "elysia/ws"
8
9
  import { zodToJsonSchema } from "zod-to-json-schema"
@@ -24,6 +25,11 @@ import {
24
25
  resolveApiBrowserPublicOrigin,
25
26
  type SixbApiBrowserPolicy,
26
27
  } from "./auth/browser-origin"
28
+ import {
29
+ type ClientAddressResolver,
30
+ createClientAddressResolver,
31
+ PRIVATE_NETWORKS,
32
+ } from "./auth/client-address"
27
33
  import { CSRF_TOKEN_RESPONSE_HEADER_NAME } from "./auth/csrf"
28
34
  import type { SixbAuthExperienceOptions } from "./auth/experience"
29
35
  import { ServerAuthGuard } from "./auth/guard"
@@ -36,10 +42,13 @@ import {
36
42
  type SixbSharedAccessOptions,
37
43
  } from "./auth/shared-access"
38
44
  import {
39
- SIXB_BEARER_SECURITY_SCHEME,
40
- SIXB_BEARER_SECURITY_SCHEME_ID,
45
+ SIXB_ACCESS_TOKEN_SECURITY_SCHEME,
46
+ SIXB_ACCESS_TOKEN_SECURITY_SCHEME_ID,
41
47
  SIXB_CSRF_SECURITY_SCHEME,
42
48
  SIXB_CSRF_SECURITY_SCHEME_ID,
49
+ SIXB_SESSION_SECURITY_REQUIREMENT,
50
+ SIXB_SESSION_SECURITY_SCHEME,
51
+ SIXB_SESSION_SECURITY_SCHEME_ID,
43
52
  SIXB_SHARED_GRANT_SECURITY_SCHEME,
44
53
  SIXB_SHARED_GRANT_SECURITY_SCHEME_ID,
45
54
  } from "./openapi/security"
@@ -61,6 +70,11 @@ export interface SixbServerOptions {
61
70
  authExperience?: SixbAuthExperienceOptions
62
71
  /** Optional server limits for short-lived shared-access sessions. */
63
72
  sharedAccess?: SixbSharedAccessOptions
73
+ /**
74
+ * Proxies whose `x-forwarded-for` entries identify the client: IP addresses, CIDR ranges, or
75
+ * `"private"` for loopback, private, and link-local networks. Defaults to `["private"]`.
76
+ */
77
+ trustedProxies?: readonly string[]
64
78
  }
65
79
 
66
80
  export function createSixbServer(options: SixbServerOptions): SixbServer {
@@ -77,6 +91,7 @@ export class SixbServer {
77
91
  private readonly authRedirectContextResolver: ResolveAuthRedirectContext
78
92
  private readonly authExperience?: SixbAuthExperienceOptions
79
93
  private readonly sharedAccessOptions: SixbSharedAccessOptions
94
+ private readonly resolveClientAddress: ClientAddressResolver
80
95
  private app: SixbApp | null = null
81
96
  private bunServer: ReturnType<typeof Bun.serve> | null = null
82
97
  private maintenance: OntologyMaintenanceHandle | null = null
@@ -93,6 +108,9 @@ export class SixbServer {
93
108
  )
94
109
  this.authExperience = options.authExperience
95
110
  this.sharedAccessOptions = options.sharedAccess ?? {}
111
+ this.resolveClientAddress = createClientAddressResolver(
112
+ options.trustedProxies ?? [PRIVATE_NETWORKS]
113
+ )
96
114
  }
97
115
 
98
116
  getHost(): SixbHostView {
@@ -154,6 +172,7 @@ export class SixbServer {
154
172
  this.bunServer = startApiServer(this.app, {
155
173
  host: this.hostname,
156
174
  port: this.port,
175
+ resolveClientAddress: this.resolveClientAddress,
157
176
  })
158
177
  } catch (error) {
159
178
  this.app = null
@@ -377,11 +396,14 @@ export function createSixbApi(server: SixbServer) {
377
396
  components: {
378
397
  securitySchemes: {
379
398
  [SIXB_CSRF_SECURITY_SCHEME_ID]: SIXB_CSRF_SECURITY_SCHEME,
380
- [SIXB_BEARER_SECURITY_SCHEME_ID]: SIXB_BEARER_SECURITY_SCHEME,
399
+ [SIXB_SESSION_SECURITY_SCHEME_ID]: SIXB_SESSION_SECURITY_SCHEME,
400
+ [SIXB_ACCESS_TOKEN_SECURITY_SCHEME_ID]: SIXB_ACCESS_TOKEN_SECURITY_SCHEME,
381
401
  [SIXB_SHARED_GRANT_SECURITY_SCHEME_ID]: SIXB_SHARED_GRANT_SECURITY_SCHEME,
382
402
  },
383
403
  schemas: ObjectQueryOpenApiSchemas,
384
404
  },
405
+ // Every operation needs a session unless it says otherwise; public ones declare `[]`.
406
+ security: SIXB_SESSION_SECURITY_REQUIREMENT,
385
407
  tags: OPENAPI_TAG_METADATA,
386
408
  },
387
409
  swagger: {
@@ -498,12 +520,20 @@ function startApiServer(
498
520
  options: {
499
521
  readonly host: string
500
522
  readonly port: number
523
+ readonly resolveClientAddress: ClientAddressResolver
501
524
  }
502
525
  ) {
503
526
  const bunServer = Bun.serve({
504
527
  port: options.port,
505
528
  hostname: options.host,
506
- fetch: (request) => app.fetch(request),
529
+ fetch: (request: Request, server: Server<unknown>) => {
530
+ const socketAddress = server.requestIP(request)?.address
531
+ if (socketAddress) {
532
+ const forwardedFor = request.headers.get("x-forwarded-for")
533
+ setRequestClientAddress(request, options.resolveClientAddress(socketAddress, forwardedFor))
534
+ }
535
+ return app.fetch(request)
536
+ },
507
537
  websocket: getElysiaWsHandler(app),
508
538
  } as Parameters<typeof Bun.serve>[0])
509
539
 
package/src/utils/ws.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { OntologySource } from "@sixb/core"
2
1
  import type { Sixb } from "@sixb/core/internal/request-execution"
3
2
 
4
3
  export function safeSend(target: { send: (message: string) => void }, payload: unknown): void {
@@ -16,10 +15,10 @@ export function wsStateKey(ws: object): object {
16
15
  }
17
16
 
18
17
  /** The execution SDK attached once when the WebSocket request crosses the auth boundary. */
19
- export function wsRequestSixb(ws: object): Sixb<readonly OntologySource[]> | null {
18
+ export function wsRequestSixb(ws: object): Sixb | null {
20
19
  const data = (
21
20
  ws as {
22
- data?: { sixb?: Sixb<readonly OntologySource[]> | null }
21
+ data?: { sixb?: Sixb | null }
23
22
  }
24
23
  ).data
25
24
  return data?.sixb ?? null