@sixb/server 0.1.10 → 0.1.12

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 (65) 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 +224 -51
  5. package/dist/index.js.map +19 -19
  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 +123 -34
  11. package/dist/routes/agents.d.ts.map +1 -1
  12. package/dist/routes/ai-accounting.d.ts.map +1 -1
  13. package/dist/routes/auth.d.ts +2 -2
  14. package/dist/routes/connector-connection-runs.d.ts +138 -4
  15. package/dist/routes/connector-connection-runs.d.ts.map +1 -1
  16. package/dist/routes/datasets.d.ts +8 -8
  17. package/dist/routes/files.d.ts +3 -1
  18. package/dist/routes/files.d.ts.map +1 -1
  19. package/dist/routes/models.d.ts +1 -1
  20. package/dist/routes/objects.d.ts +18 -5
  21. package/dist/routes/objects.d.ts.map +1 -1
  22. package/dist/routes/ontology.d.ts +24 -12
  23. package/dist/routes/ontology.d.ts.map +1 -1
  24. package/dist/routes/syncs.d.ts +5 -5
  25. package/dist/routes/workflows.d.ts +10 -6
  26. package/dist/routes/workflows.d.ts.map +1 -1
  27. package/dist/schemas/agents.d.ts +205 -100
  28. package/dist/schemas/agents.d.ts.map +1 -1
  29. package/dist/schemas/ai-accounting.d.ts +692 -104
  30. package/dist/schemas/ai-accounting.d.ts.map +1 -1
  31. package/dist/schemas/ai-usage.d.ts +2 -2
  32. package/dist/schemas/auth.d.ts +6 -6
  33. package/dist/schemas/common.d.ts +15 -0
  34. package/dist/schemas/common.d.ts.map +1 -1
  35. package/dist/schemas/connectors.d.ts +0 -3
  36. package/dist/schemas/connectors.d.ts.map +1 -1
  37. package/dist/schemas/datasets.d.ts +22 -22
  38. package/dist/schemas/files.d.ts +17 -8
  39. package/dist/schemas/files.d.ts.map +1 -1
  40. package/dist/schemas/models.d.ts +8 -8
  41. package/dist/schemas/objects.d.ts +13 -1
  42. package/dist/schemas/objects.d.ts.map +1 -1
  43. package/dist/schemas/ontology.d.ts +99 -49
  44. package/dist/schemas/ontology.d.ts.map +1 -1
  45. package/dist/schemas/syncs.d.ts +12 -12
  46. package/dist/schemas/workflows.d.ts +50 -50
  47. package/dist/server.d.ts.map +1 -1
  48. package/package.json +6 -5
  49. package/src/auth/browser-origin.ts +50 -1
  50. package/src/connectors/http.ts +0 -1
  51. package/src/models/display.ts +3 -2
  52. package/src/routes/agents.ts +48 -6
  53. package/src/routes/ai-accounting.ts +1 -0
  54. package/src/routes/connector-connection-runs.ts +37 -1
  55. package/src/routes/files.ts +2 -1
  56. package/src/routes/objects.ts +46 -2
  57. package/src/routes/ontology.ts +15 -5
  58. package/src/schemas/agents.ts +9 -0
  59. package/src/schemas/ai-accounting.ts +19 -1
  60. package/src/schemas/common.ts +5 -0
  61. package/src/schemas/connectors.ts +0 -1
  62. package/src/schemas/files.ts +8 -1
  63. package/src/schemas/objects.ts +30 -12
  64. package/src/schemas/ontology.ts +15 -6
  65. package/src/server.ts +2 -0
@@ -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
@@ -49,6 +49,7 @@ const ObjectFileContentQuerySchema = FileContentQuerySchema.extend({
49
49
  })
50
50
 
51
51
  function serializeObject(row: {
52
+ score?: number
52
53
  primaryId: string
53
54
  objectTypeId: string
54
55
  properties: Record<string, unknown>
@@ -56,6 +57,7 @@ function serializeObject(row: {
56
57
  updatedAt: Date
57
58
  }) {
58
59
  return {
60
+ ...(row.score === undefined ? {} : { score: row.score }),
59
61
  primaryId: row.primaryId,
60
62
  objectTypeId: row.objectTypeId,
61
63
  properties: row.properties,
@@ -181,8 +183,7 @@ function handleObjectQueryError(error: unknown, set: { status?: number | string
181
183
  }
182
184
  }
183
185
 
184
- set.status = 500
185
- return { error: error instanceof Error ? error.message : String(error) }
186
+ return handleRouteError(error, set)
186
187
  }
187
188
 
188
189
  function formatZodIssuePath(path: readonly (string | number)[]): string {
@@ -408,6 +409,7 @@ export function registerObjectRoutes(app: Elysia, host: SixbHostView) {
408
409
  const result = await requireRequestSixb(context).objects.executeQuery({
409
410
  query: parsed.query,
410
411
  includeTotal: parsed.includeTotal,
412
+ signal: context.request.signal,
411
413
  })
412
414
 
413
415
  return {
@@ -460,6 +462,20 @@ export function registerObjectRoutes(app: Elysia, host: SixbHostView) {
460
462
  },
461
463
  },
462
464
  },
465
+ 429: {
466
+ description: "AI usage limit exceeded or unavailable",
467
+ headers: {
468
+ "Retry-After": {
469
+ description: "Seconds until the budget period resets, when known",
470
+ schema: { type: "integer" },
471
+ },
472
+ },
473
+ content: {
474
+ "application/json": {
475
+ schema: { $ref: "#/components/schemas/AiUsageLimitErrorResponse" },
476
+ },
477
+ },
478
+ },
463
479
  500: {
464
480
  description: "Response for status 500",
465
481
  content: {
@@ -605,6 +621,20 @@ export function registerObjectRoutes(app: Elysia, host: SixbHostView) {
605
621
  },
606
622
  },
607
623
  },
624
+ 429: {
625
+ description: "AI usage limit exceeded or unavailable",
626
+ headers: {
627
+ "Retry-After": {
628
+ description: "Seconds until the budget period resets, when known",
629
+ schema: { type: "integer" },
630
+ },
631
+ },
632
+ content: {
633
+ "application/json": {
634
+ schema: { $ref: "#/components/schemas/AiUsageLimitErrorResponse" },
635
+ },
636
+ },
637
+ },
608
638
  500: {
609
639
  description: "Response for status 500",
610
640
  content: {
@@ -674,6 +704,20 @@ export function registerObjectRoutes(app: Elysia, host: SixbHostView) {
674
704
  },
675
705
  },
676
706
  },
707
+ 429: {
708
+ description: "AI usage limit exceeded or unavailable",
709
+ headers: {
710
+ "Retry-After": {
711
+ description: "Seconds until the budget period resets, when known",
712
+ schema: { type: "integer" },
713
+ },
714
+ },
715
+ content: {
716
+ "application/json": {
717
+ schema: { $ref: "#/components/schemas/AiUsageLimitErrorResponse" },
718
+ },
719
+ },
720
+ },
677
721
  500: {
678
722
  description: "Response for status 500",
679
723
  content: {
@@ -34,11 +34,21 @@ function serializeSearch(
34
34
  title: search.title,
35
35
  defaultText: search.defaultText ? [...search.defaultText] : undefined,
36
36
  exact: search.exact ? [...search.exact] : undefined,
37
- vector: search.vector
38
- ? {
39
- property: search.vector.property,
40
- source: [...search.vector.source],
41
- }
37
+ vectors: search.vectors
38
+ ? Object.fromEntries(
39
+ Object.entries(search.vectors).map(([name, profile]) => [
40
+ name,
41
+ {
42
+ source: [...profile.source],
43
+ model: {
44
+ providerId: profile.model.providerId,
45
+ modelId: profile.model.modelId,
46
+ dimensions: profile.model.definition.dimensions,
47
+ representation: profile.model.definition.representation,
48
+ },
49
+ },
50
+ ])
51
+ )
42
52
  : undefined,
43
53
  }
44
54
  }
@@ -90,14 +90,23 @@ export const CreateAgentThreadBodySchema = z
90
90
  .object({
91
91
  title: z.string().trim().min(1).optional(),
92
92
  threadId: z.string().trim().min(1).optional(),
93
+ sandbox: z.record(z.string(), JsonValueSchema).optional(),
93
94
  })
94
95
  .strict()
95
96
 
96
97
  export const AgentThreadSchema = z.object({
98
+ sandboxState: z
99
+ .object({
100
+ name: z.string(),
101
+ status: z.enum(["new", "busy", "ready", "blocked", "unavailable"]),
102
+ initialized: z.boolean(),
103
+ })
104
+ .optional(),
97
105
  id: z.string(),
98
106
  projectId: z.string(),
99
107
  ownerPrincipal: AgentPrincipalSchema,
100
108
  title: z.string().optional(),
109
+ sandboxParams: z.record(z.string(), JsonValueSchema).optional(),
101
110
  status: AgentThreadStatusSchema,
102
111
  activeRunId: z.string().nullable(),
103
112
  lastMessageAt: z.string().optional(),
@@ -41,7 +41,25 @@ export const AiCostSummarySchema = z.object({
41
41
 
42
42
  const AiAccountingAggregateSchema = z.object({
43
43
  modelCallCount: z.number().int().nonnegative(),
44
- usage: AiUsageSummarySchema,
44
+ usage: AiUsageSummarySchema.describe(
45
+ "Sums of reported meters; unreported meters are absent. totalTokens sums available input and output counts and is a lower bound when coverage is incomplete."
46
+ ),
47
+ usageCoverage: z.object({
48
+ completeCallCount: z
49
+ .number()
50
+ .int()
51
+ .nonnegative()
52
+ .describe("Calls reporting both inputTokens and outputTokens."),
53
+ fieldCallCounts: z.object({
54
+ inputTokens: z.number().int().nonnegative(),
55
+ outputTokens: z.number().int().nonnegative(),
56
+ uncachedInputTokens: z.number().int().nonnegative(),
57
+ cacheReadInputTokens: z.number().int().nonnegative(),
58
+ cacheWriteInputTokens: z.number().int().nonnegative(),
59
+ textOutputTokens: z.number().int().nonnegative(),
60
+ reasoningOutputTokens: z.number().int().nonnegative(),
61
+ }),
62
+ }),
45
63
  costs: AiCostSummarySchema,
46
64
  })
47
65
 
@@ -84,3 +84,8 @@ export const jsonValueOpenApiOverride: OverrideCallback = (def) => {
84
84
 
85
85
  return ignoreOverride
86
86
  }
87
+
88
+ export const AiUsageLimitErrorResponseSchema = codedErrorResponseSchema([
89
+ "ai.usage_limit_exceeded",
90
+ "ai.usage_limit_unavailable",
91
+ ]).extend({ details: JsonValueSchema.optional() })
@@ -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"),
@@ -1,10 +1,18 @@
1
1
  import type { ElysiaOpenAPIConfig } from "@elysiajs/openapi"
2
2
  import { z } from "zod"
3
- import { JsonValueSchema } from "./common"
3
+ import { zodToJsonSchema } from "zod-to-json-schema"
4
+ import {
5
+ AiUsageLimitErrorResponseSchema,
6
+ JsonValueSchema,
7
+ jsonValueOpenApiOverride,
8
+ } from "./common"
4
9
 
5
- type OpenApiSchemas = NonNullable<
6
- NonNullable<ElysiaOpenAPIConfig["documentation"]>["components"]
7
- >["schemas"]
10
+ type OpenApiSchema = NonNullable<
11
+ NonNullable<NonNullable<ElysiaOpenAPIConfig["documentation"]>["components"]>["schemas"]
12
+ >[string]
13
+ // The plugin supports both dialects; nullable identifies the 3.0 schemas we emit.
14
+ type OpenApi3Schema = Extract<OpenApiSchema, { nullable?: boolean }>
15
+ type OpenApiSchemas = Record<string, OpenApi3Schema>
8
16
 
9
17
  export const ObjectParamsSchema = z.object({
10
18
  objectTypeId: z.string().min(1),
@@ -226,8 +234,8 @@ export const ObjectQuerySchema: z.ZodType<unknown> = z.lazy(() =>
226
234
  .object({
227
235
  kind: z.literal("vector"),
228
236
  input: ObjectQuerySchema,
229
- vector: z.array(z.number().finite()),
230
- propertyId: z.string().min(1),
237
+ vector: z.string().min(1).max(8000),
238
+ profile: z.string().min(1),
231
239
  k: z.number().int().positive(),
232
240
  })
233
241
  .strict(),
@@ -331,6 +339,7 @@ export const ObjectQueryLinksRequestSchema = z
331
339
  .strict()
332
340
 
333
341
  export const TwinObjectSchema = z.object({
342
+ score: z.number().finite().optional(),
334
343
  primaryId: z.string(),
335
344
  objectTypeId: z.string(),
336
345
  properties: z.record(z.unknown()),
@@ -345,7 +354,10 @@ export const ObjectListResponseSchema = z.object({
345
354
  })
346
355
 
347
356
  const anyJsonValueSchema = {}
348
- const stringArraySchema = { type: "array", items: { type: "string", minLength: 1 } }
357
+ const stringArraySchema = {
358
+ type: "array",
359
+ items: { type: "string", minLength: 1 },
360
+ } satisfies OpenApi3Schema
349
361
  const objectQueryRef = { $ref: "#/components/schemas/ObjectQuery" }
350
362
  const objectQueryPredicateRef = { $ref: "#/components/schemas/ObjectQueryPredicate" }
351
363
  const objectQuerySortFieldRef = { $ref: "#/components/schemas/ObjectQuerySortField" }
@@ -357,7 +369,7 @@ const objectRefSchemaRef = { $ref: "#/components/schemas/ObjectRef" }
357
369
  * OpenAPI config inlines refs. Keep the HTTP validator above in Zod, and provide
358
370
  * the recursive request contract directly for generated clients and docs.
359
371
  */
360
- export const ObjectQueryOpenApiSchemas = {
372
+ export const ObjectQueryOpenApiSchemas: OpenApiSchemas = {
361
373
  ErrorResponse: {
362
374
  type: "object",
363
375
  required: ["error"],
@@ -371,6 +383,7 @@ export const ObjectQueryOpenApiSchemas = {
371
383
  required: ["primaryId", "objectTypeId", "properties", "createdAt", "updatedAt"],
372
384
  additionalProperties: false,
373
385
  properties: {
386
+ score: { type: "number" },
374
387
  primaryId: { type: "string" },
375
388
  objectTypeId: { type: "string" },
376
389
  properties: { type: "object", additionalProperties: true },
@@ -534,6 +547,11 @@ export const ObjectQueryOpenApiSchemas = {
534
547
  nextPageToken: { type: "string" },
535
548
  },
536
549
  },
550
+ AiUsageLimitErrorResponse: zodToJsonSchema(AiUsageLimitErrorResponseSchema, {
551
+ target: "openApi3",
552
+ $refStrategy: "none",
553
+ override: jsonValueOpenApiOverride,
554
+ }) as OpenApi3Schema,
537
555
  ObjectQueryErrorResponse: {
538
556
  type: "object",
539
557
  required: ["error"],
@@ -674,13 +692,13 @@ export const ObjectQueryOpenApiSchemas = {
674
692
  },
675
693
  {
676
694
  type: "object",
677
- required: ["kind", "input", "vector", "propertyId", "k"],
695
+ required: ["kind", "input", "vector", "profile", "k"],
678
696
  additionalProperties: false,
679
697
  properties: {
680
698
  kind: { type: "string", enum: ["vector"] },
681
699
  input: objectQueryRef,
682
- vector: { type: "array", items: { type: "number" } },
683
- propertyId: { type: "string", minLength: 1 },
700
+ vector: { type: "string", minLength: 1, maxLength: 8000 },
701
+ profile: { type: "string", minLength: 1 },
684
702
  k: { type: "integer", minimum: 1 },
685
703
  },
686
704
  },
@@ -860,4 +878,4 @@ export const ObjectQueryOpenApiSchemas = {
860
878
  ],
861
879
  discriminator: { propertyName: "kind" },
862
880
  },
863
- } as unknown as OpenApiSchemas
881
+ }
@@ -20,7 +20,6 @@ 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(),
@@ -64,11 +63,21 @@ export const ObjectTypeSchema = z.object({
64
63
  title: z.string().optional(),
65
64
  defaultText: z.array(z.string()).optional(),
66
65
  exact: z.array(z.string()).optional(),
67
- vector: z
68
- .object({
69
- property: z.string(),
70
- source: z.array(z.string()),
71
- })
66
+ vectors: z
67
+ .record(
68
+ z.string(),
69
+ z.object({
70
+ source: z.array(z.string()),
71
+ model: z.object({
72
+ providerId: z.string(),
73
+ modelId: z.string(),
74
+ dimensions: z.number().int().positive(),
75
+ representation: z
76
+ .object({ name: z.string(), version: z.string().optional() })
77
+ .optional(),
78
+ }),
79
+ })
80
+ )
72
81
  .optional(),
73
82
  })
74
83
  .optional(),
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",