@sixb/server 0.1.10 → 0.1.11

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 (38) hide show
  1. package/README.md +19 -0
  2. package/dist/auth/browser-origin.d.ts.map +1 -1
  3. package/dist/connectors/http.d.ts.map +1 -1
  4. package/dist/index.js +78 -25
  5. package/dist/index.js.map +11 -11
  6. package/dist/models/display.d.ts +2 -2
  7. package/dist/models/display.d.ts.map +1 -1
  8. package/dist/routes/action-runs.d.ts +2 -0
  9. package/dist/routes/action-runs.d.ts.map +1 -1
  10. package/dist/routes/agents.d.ts +2 -0
  11. package/dist/routes/agents.d.ts.map +1 -1
  12. package/dist/routes/auth.d.ts +2 -2
  13. package/dist/routes/connector-connection-runs.d.ts +138 -4
  14. package/dist/routes/connector-connection-runs.d.ts.map +1 -1
  15. package/dist/routes/files.d.ts +3 -1
  16. package/dist/routes/files.d.ts.map +1 -1
  17. package/dist/routes/objects.d.ts +2 -0
  18. package/dist/routes/objects.d.ts.map +1 -1
  19. package/dist/routes/workflows.d.ts +4 -0
  20. package/dist/routes/workflows.d.ts.map +1 -1
  21. package/dist/schemas/auth.d.ts +6 -6
  22. package/dist/schemas/connectors.d.ts +0 -3
  23. package/dist/schemas/connectors.d.ts.map +1 -1
  24. package/dist/schemas/files.d.ts +17 -8
  25. package/dist/schemas/files.d.ts.map +1 -1
  26. package/dist/schemas/objects.d.ts +5 -1
  27. package/dist/schemas/objects.d.ts.map +1 -1
  28. package/dist/server.d.ts.map +1 -1
  29. package/package.json +6 -5
  30. package/src/auth/browser-origin.ts +50 -1
  31. package/src/connectors/http.ts +0 -1
  32. package/src/models/display.ts +3 -2
  33. package/src/routes/connector-connection-runs.ts +37 -1
  34. package/src/routes/files.ts +2 -1
  35. package/src/schemas/connectors.ts +0 -1
  36. package/src/schemas/files.ts +8 -1
  37. package/src/schemas/objects.ts +12 -6
  38. package/src/server.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sixb/server",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "HTTP and WebSocket API server for Sixb",
5
5
  "keywords": [
6
6
  "sixb",
@@ -26,24 +26,25 @@
26
26
  "build": "bun ../../scripts/build-package.ts",
27
27
  "typecheck": "tsc --noEmit",
28
28
  "test": "bun test",
29
+ "test:e2e": "bun test ./tests/*.e2e.ts",
29
30
  "generate:openapi": "bun run scripts/generate-openapi.ts",
30
31
  "prepack": "bun run build"
31
32
  },
32
33
  "dependencies": {
33
34
  "@elysiajs/cors": "^1.2.0",
34
- "@elysiajs/openapi": "^1.4.0",
35
+ "@elysiajs/openapi": "^1.4.16",
35
36
  "elysia": "^1.2.0",
36
37
  "zod": "^3.24.0",
37
38
  "zod-to-json-schema": "^3.24.0"
38
39
  },
39
40
  "peerDependencies": {
40
- "@sixb/core": "0.1.10"
41
+ "@sixb/core": "0.1.11"
41
42
  },
42
43
  "devDependencies": {
43
44
  "@sixb/auth-magic-link": "0.1.4",
44
45
  "@sixb/auth-oidc": "0.1.3",
45
- "@sixb/core": "0.1.10",
46
- "@sixb/sqlite": "0.1.10",
46
+ "@sixb/core": "0.1.11",
47
+ "@sixb/sqlite": "0.1.11",
47
48
  "@types/bun": "latest",
48
49
  "typescript": "^5.7.0"
49
50
  },
@@ -5,6 +5,12 @@ import {
5
5
  isValidAuthSessionAudience,
6
6
  resolveAuthSessionAudience,
7
7
  } from "@sixb/core"
8
+ import { matchesPathPattern, normalizeRoutePath, SIXB_API_ROUTES } from "@sixb/core/internal/http"
9
+
10
+ const fileNavigationRoutes = SIXB_API_ROUTES.filter(
11
+ (route) =>
12
+ (route.method === "GET" || route.method === "HEAD") && route.path.endsWith("/files/content")
13
+ )
8
14
 
9
15
  export interface SixbBrowserOrigin {
10
16
  readonly origin: string
@@ -137,12 +143,14 @@ export function resolveApiBrowserAuthContext(
137
143
  request: Request
138
144
  ): RequestAuthContext {
139
145
  const origin = normalizeRequestOrigin(request)
146
+ const fileAudience = resolveFileNavigationAudience(policy, request)
140
147
  if (!origin) {
141
- return { audience: policy.apiOriginAudience, absoluteReturnTo: true }
148
+ return { audience: fileAudience ?? policy.apiOriginAudience, absoluteReturnTo: true }
142
149
  }
143
150
 
144
151
  const allowed = findAllowedBrowserOrigin(policy, origin)
145
152
  if (allowed) {
153
+ assertFileAudienceMatchesOrigin(fileAudience, allowed.audience)
146
154
  return {
147
155
  audience: allowed.audience,
148
156
  browserOrigin: allowed.origin,
@@ -151,12 +159,53 @@ export function resolveApiBrowserAuthContext(
151
159
  }
152
160
 
153
161
  if (isSameOriginApiRequest(policy, origin, request)) {
162
+ assertFileAudienceMatchesOrigin(fileAudience, policy.apiOriginAudience)
154
163
  return { audience: policy.apiOriginAudience, browserOrigin: origin, absoluteReturnTo: true }
155
164
  }
156
165
 
157
166
  throw new BrowserOriginError(`[SixbServer] Browser origin '${origin}' is not allowed.`)
158
167
  }
159
168
 
169
+ // A URL audience selects credentials, never grants authority. Only file GET/HEAD
170
+ // routes accept it; Origin remains authoritative whenever the browser sends one.
171
+ function resolveFileNavigationAudience(
172
+ policy: ResolvedSixbApiBrowserPolicy,
173
+ request: Request
174
+ ): AuthSessionAudience | undefined {
175
+ const url = new URL(request.url)
176
+ if (
177
+ !fileNavigationRoutes.some(
178
+ (route) =>
179
+ route.method === request.method &&
180
+ matchesPathPattern(normalizeRoutePath(url.pathname), route.path)
181
+ )
182
+ ) {
183
+ return undefined
184
+ }
185
+ const values = url.searchParams.getAll("audience")
186
+ if (values.length === 0) return undefined
187
+ const audience = values[0]
188
+ if (
189
+ values.length !== 1 ||
190
+ !audience ||
191
+ !isValidAuthSessionAudience(audience) ||
192
+ (audience !== policy.apiOriginAudience &&
193
+ !policy.allowedOrigins.some((entry) => entry.audience === audience))
194
+ ) {
195
+ throw new BrowserOriginError("[SixbServer] File navigation audience is not allowed.")
196
+ }
197
+ return audience
198
+ }
199
+
200
+ function assertFileAudienceMatchesOrigin(
201
+ audience: AuthSessionAudience | undefined,
202
+ originAudience: AuthSessionAudience
203
+ ): void {
204
+ if (audience !== undefined && audience !== originAudience) {
205
+ throw new BrowserOriginError("[SixbServer] File navigation audience conflicts with Origin.")
206
+ }
207
+ }
208
+
160
209
  export function isAllowedApiBrowserOrigin(
161
210
  policy: ResolvedSixbApiBrowserPolicy,
162
211
  request: Request
@@ -76,7 +76,6 @@ export function serializeConnectorConnectionRun(
76
76
  status: "waiting",
77
77
  waitingFor: "account_selection",
78
78
  accounts: [...run.accounts],
79
- expiresAt: toIsoString(run.expiresAt),
80
79
  }
81
80
  }
82
81
  if (run.status === "succeeded") {
@@ -29,6 +29,7 @@ export async function languageModelDisplay(entry: LanguageModelEntry) {
29
29
  }
30
30
  const gateway = entry.provider === "vercel-ai-gateway"
31
31
  const publisherId = gateway ? entry.modelId.split("/")[0]! : entry.provider
32
+ const via = definition.via ?? (gateway ? "AI Gateway" : undefined)
32
33
  const capabilities = definition.capabilities
33
34
  const media = capabilities.inputMediaTypes
34
35
  const input = ["text"]
@@ -43,8 +44,8 @@ export async function languageModelDisplay(entry: LanguageModelEntry) {
43
44
  return {
44
45
  name: definition.name ?? entry.modelId,
45
46
  ...(definition.description === undefined ? {} : { description: definition.description }),
46
- publisher: { id: publisherId, name: publisherName(publisherId) },
47
- ...(gateway ? { via: "AI Gateway" } : {}),
47
+ publisher: definition.publisher ?? { id: publisherId, name: publisherName(publisherId) },
48
+ ...(via === undefined ? {} : { via }),
48
49
  capabilities: {
49
50
  input,
50
51
  output: ["text"],
@@ -45,6 +45,39 @@ export function registerConnectorConnectionRunRoutes(
45
45
  options: ConnectorConnectionRouteOptions
46
46
  ) {
47
47
  return app
48
+ .get(
49
+ "/api/connectors/:connectorId/connection-runs",
50
+ async (context) => {
51
+ const { params, set } = context
52
+ try {
53
+ const runtime = connectorRouteRuntime(
54
+ host,
55
+ requireRequestSixb(context),
56
+ params.connectorId
57
+ )
58
+ return (await runtime.listPendingConnectionRuns(params.connectorId)).map(
59
+ serializeConnectorConnectionRun
60
+ )
61
+ } catch (error) {
62
+ return handleConnectorRouteError(error, set)
63
+ }
64
+ },
65
+ {
66
+ params: ConnectorConnectionParamsSchema.pick({ connectorId: true }),
67
+ response: {
68
+ 200: ConnectorConnectionRunSchema.array(),
69
+ 400: ConnectorBadRequestResponseSchema,
70
+ 403: ErrorResponseSchema,
71
+ 404: ConnectorNotFoundResponseSchema,
72
+ 500: ConnectorInternalErrorResponseSchema,
73
+ },
74
+ detail: {
75
+ summary: "List the initiating user's pending connector connection runs",
76
+ tags: [OPENAPI_TAGS.connectorConnectionRuns.name],
77
+ operationId: "listPendingConnectorConnectionRuns",
78
+ },
79
+ }
80
+ )
48
81
  .post(
49
82
  "/api/connectors/:connectorId/connection-runs",
50
83
  async (context) => {
@@ -282,7 +315,10 @@ export function registerConnectorConnectionRunRoutes(
282
315
  )
283
316
  .get(
284
317
  "/auth/connectors/callback",
285
- async ({ request, set }) => {
318
+ async ({ request, set, server }) => {
319
+ // Provider deadlines bound this operation; preserve its callback response.
320
+ server?.timeout(request, 0)
321
+
286
322
  let callbackCookie: ReturnType<typeof readConnectorCallbackCookie> | undefined
287
323
  try {
288
324
  const parameters = new URL(request.url).searchParams
@@ -467,6 +467,7 @@ function fileUploadResponse(session: FileUploadSession) {
467
467
  strategy: "multipart",
468
468
  uploadId: session.id,
469
469
  partSizeBytes: session.providerUpload.partSizeBytes,
470
+ partReceipt: session.providerUpload.partReceipt ?? "etag",
470
471
  expiresAt: session.providerUpload.expiresAt.toISOString(),
471
472
  }
472
473
  }
@@ -534,7 +535,7 @@ async function completeProviderUpload(input: {
534
535
  readonly session: FileUploadSession
535
536
  readonly expectedDigest?: BlobDigest
536
537
  readonly expectedSizeBytes?: number
537
- readonly parts: readonly { readonly partNumber: number; readonly etag: string }[] | undefined
538
+ readonly parts: readonly { readonly partNumber: number; readonly etag?: string }[] | undefined
538
539
  readonly blobStorage: SixbHostView["blobStorage"]
539
540
  }): Promise<FileRef> {
540
541
  const { blobStorage, session } = input
@@ -119,7 +119,6 @@ export const ConnectorConnectionRunSchema = z.union([
119
119
  status: z.literal("waiting"),
120
120
  waitingFor: z.literal("account_selection"),
121
121
  accounts: z.array(ConnectorAccountSchema),
122
- expiresAt: z.string().datetime(),
123
122
  }),
124
123
  ConnectorConnectionRunBaseSchema.extend({
125
124
  status: z.literal("succeeded"),
@@ -46,6 +46,7 @@ export const DirectPutFileUploadSchema = z.object({
46
46
 
47
47
  export const MultipartFileUploadSchema = z.object({
48
48
  strategy: z.literal("multipart"),
49
+ partReceipt: z.enum(["etag", "none"]),
49
50
  uploadId: z.string(),
50
51
  partSizeBytes: z.number().int().positive(),
51
52
  expiresAt: z.string(),
@@ -67,7 +68,7 @@ export const SignedFileUploadPartSchema = z.object({
67
68
 
68
69
  export const FileUploadPartSchema = z.object({
69
70
  partNumber: z.number().int().positive(),
70
- etag: z.string(),
71
+ etag: z.string().min(1).optional(),
71
72
  })
72
73
 
73
74
  export const CompleteFileUploadBodySchema = z.object({
@@ -77,6 +78,12 @@ export const CompleteFileUploadBodySchema = z.object({
77
78
  })
78
79
 
79
80
  export const FileContentQuerySchema = z.object({
81
+ audience: z
82
+ .enum(["atlas", "app"])
83
+ .optional()
84
+ .describe(
85
+ "Session audience for file navigation without Origin; must match Origin when present"
86
+ ),
80
87
  path: z.string().min(1),
81
88
  disposition: z.enum(["inline", "attachment"]).optional(),
82
89
  v: z.string().optional().describe("Client cache key; the route still resolves the current file"),
@@ -2,9 +2,12 @@ import type { ElysiaOpenAPIConfig } from "@elysiajs/openapi"
2
2
  import { z } from "zod"
3
3
  import { JsonValueSchema } from "./common"
4
4
 
5
- type OpenApiSchemas = NonNullable<
6
- NonNullable<ElysiaOpenAPIConfig["documentation"]>["components"]
7
- >["schemas"]
5
+ type OpenApiSchema = NonNullable<
6
+ NonNullable<NonNullable<ElysiaOpenAPIConfig["documentation"]>["components"]>["schemas"]
7
+ >[string]
8
+ // The plugin supports both dialects; nullable identifies the 3.0 schemas we emit.
9
+ type OpenApi3Schema = Extract<OpenApiSchema, { nullable?: boolean }>
10
+ type OpenApiSchemas = Record<string, OpenApi3Schema>
8
11
 
9
12
  export const ObjectParamsSchema = z.object({
10
13
  objectTypeId: z.string().min(1),
@@ -345,7 +348,10 @@ export const ObjectListResponseSchema = z.object({
345
348
  })
346
349
 
347
350
  const anyJsonValueSchema = {}
348
- const stringArraySchema = { type: "array", items: { type: "string", minLength: 1 } }
351
+ const stringArraySchema = {
352
+ type: "array",
353
+ items: { type: "string", minLength: 1 },
354
+ } satisfies OpenApi3Schema
349
355
  const objectQueryRef = { $ref: "#/components/schemas/ObjectQuery" }
350
356
  const objectQueryPredicateRef = { $ref: "#/components/schemas/ObjectQueryPredicate" }
351
357
  const objectQuerySortFieldRef = { $ref: "#/components/schemas/ObjectQuerySortField" }
@@ -357,7 +363,7 @@ const objectRefSchemaRef = { $ref: "#/components/schemas/ObjectRef" }
357
363
  * OpenAPI config inlines refs. Keep the HTTP validator above in Zod, and provide
358
364
  * the recursive request contract directly for generated clients and docs.
359
365
  */
360
- export const ObjectQueryOpenApiSchemas = {
366
+ export const ObjectQueryOpenApiSchemas: OpenApiSchemas = {
361
367
  ErrorResponse: {
362
368
  type: "object",
363
369
  required: ["error"],
@@ -860,4 +866,4 @@ export const ObjectQueryOpenApiSchemas = {
860
866
  ],
861
867
  discriminator: { propertyName: "kind" },
862
868
  },
863
- } as unknown as OpenApiSchemas
869
+ }
package/src/server.ts CHANGED
@@ -366,6 +366,8 @@ export function createSixbApi(server: SixbServer) {
366
366
  openapi({
367
367
  path: "/docs",
368
368
  provider: "swagger-ui",
369
+ // zodToJsonSchema below emits OpenAPI 3.0 nullable schemas.
370
+ openapiVersion: "3.0.3",
369
371
  documentation: {
370
372
  info: {
371
373
  title: "Sixb API",