@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
@@ -13,7 +13,7 @@ import {
13
13
  } from "@sixb/core/storage"
14
14
  import type { Elysia } from "elysia"
15
15
  import { ZodError, z } from "zod"
16
- import { bearerSecurityRequirement } from "../auth/access-token-boundary"
16
+ import { accessTokenSecurityRequirement } from "../auth/access-token-boundary"
17
17
  import { type RequestAuthState, requestAuthState, requireRequestSixb } from "../auth/scope"
18
18
  import {
19
19
  createFileContentResponse,
@@ -21,7 +21,7 @@ import {
21
21
  fileContentHeadResponses,
22
22
  resolveFileRefAtPath,
23
23
  } from "../files/content"
24
- import { SIXB_CSRF_SECURITY_REQUIREMENT } from "../openapi/security"
24
+ import { SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT } from "../openapi/security"
25
25
  import { OPENAPI_TAGS } from "../openapi/tags"
26
26
  import {
27
27
  AgentDescriptorSchema,
@@ -45,7 +45,7 @@ import {
45
45
  PostAgentMessageResponseSchema,
46
46
  RetryAgentRunResponseSchema,
47
47
  } from "../schemas/agents"
48
- import { codedErrorResponseSchema, ErrorResponseSchema, JsonValueSchema } from "../schemas/common"
48
+ import { AiUsageLimitErrorResponseSchema, ErrorResponseSchema } from "../schemas/common"
49
49
  import { FileContentQuerySchema } from "../schemas/files"
50
50
  import {
51
51
  handleRouteError,
@@ -61,17 +61,18 @@ const AgentMessageFileContentQuerySchema = FileContentQuerySchema.extend({
61
61
  .regex(/^\/parts(?:\/|$)/, "Agent message file content paths must start with /parts/"),
62
62
  })
63
63
 
64
- const AiUsageLimitErrorResponseSchema = codedErrorResponseSchema([
65
- "ai.usage_limit_exceeded",
66
- "ai.usage_limit_unavailable",
67
- ]).extend({ details: JsonValueSchema.optional() })
68
-
69
64
  function serializeThread(thread: AgentThreadRecord): ReturnType<typeof AgentThreadSchema.parse> {
70
65
  return AgentThreadSchema.parse({
71
66
  id: thread.id,
72
67
  projectId: thread.projectId,
73
68
  ownerPrincipal: thread.ownerPrincipal,
74
69
  title: thread.title,
70
+ sandboxParams: thread.sandboxParams,
71
+ sandboxState: thread.sandboxState && {
72
+ name: thread.sandboxState.name,
73
+ status: thread.sandboxState.status,
74
+ initialized: thread.sandboxState.initialized,
75
+ },
75
76
  status: thread.status,
76
77
  activeRunId: thread.activeRunId,
77
78
  lastMessageAt: thread.lastMessageAt ? toIsoString(thread.lastMessageAt) : undefined,
@@ -182,6 +183,7 @@ function handleAgentRouteError(
182
183
  }
183
184
 
184
185
  if (error instanceof AgentRequestError) {
186
+ // Core performs visibility checks before workspace state transitions.
185
187
  switch (error.code) {
186
188
  case "agent_not_found":
187
189
  case "run_not_found":
@@ -190,12 +192,15 @@ function handleAgentRouteError(
190
192
  break
191
193
  case "active_run_exists":
192
194
  case "run_not_retryable":
195
+ case "sandbox_execution_unavailable":
193
196
  set.status = 409
194
197
  break
195
198
  case "authority_not_inheritable":
196
199
  set.status = 403
197
200
  break
198
201
  case "storage_unavailable":
202
+ case "sandbox_not_configured":
203
+ case "invalid_sandbox_params":
199
204
  case "agent_selector_removed":
200
205
  case "invalid_context":
201
206
  case "invalid_model_selection":
@@ -360,6 +365,7 @@ export function registerAgentRoutes(app: Elysia, host: SixbHostView) {
360
365
  const thread = await sixb.agent.threads.create({
361
366
  ...(parsed.threadId === undefined ? {} : { id: parsed.threadId }),
362
367
  ...(parsed.title === undefined ? {} : { title: parsed.title }),
368
+ ...(parsed.sandbox === undefined ? {} : { sandbox: parsed.sandbox }),
363
369
  })
364
370
 
365
371
  set.status = 201
@@ -382,7 +388,7 @@ export function registerAgentRoutes(app: Elysia, host: SixbHostView) {
382
388
  summary: "Create an agent thread",
383
389
  tags: [OPENAPI_TAGS.agentThreads.name],
384
390
  operationId: "createAgentThread",
385
- security: SIXB_CSRF_SECURITY_REQUIREMENT,
391
+ security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT,
386
392
  },
387
393
  }
388
394
  )
@@ -423,6 +429,42 @@ export function registerAgentRoutes(app: Elysia, host: SixbHostView) {
423
429
  },
424
430
  }
425
431
  )
432
+ .post(
433
+ "/api/agent-threads/:threadId/sandbox/recreate",
434
+ async (context) => {
435
+ try {
436
+ const sixb = requireRequestSixb(context)
437
+ const thread = await sixb.agent.threads.recreateSandbox(
438
+ context.params.threadId,
439
+ context.body
440
+ )
441
+ return serializeThread(thread)
442
+ } catch (error) {
443
+ if (error instanceof AgentStorageError && error.code === "invalid_state") {
444
+ context.set.status = 409
445
+ return { error: "Sandbox state changed or a run is active. Reload and try again." }
446
+ }
447
+ return handleAgentRouteError(error, context.set)
448
+ }
449
+ },
450
+ {
451
+ params: AgentThreadParamsSchema,
452
+ body: z.object({ expectedSandboxName: z.string().min(1) }).strict(),
453
+ response: {
454
+ 200: AgentThreadSchema,
455
+ 400: ErrorResponseSchema,
456
+ 404: ErrorResponseSchema,
457
+ 409: ErrorResponseSchema,
458
+ },
459
+ detail: {
460
+ summary:
461
+ "Explicitly recreate an unavailable or uncertain workspace without deleting its previous state",
462
+ operationId: "recreateAgentThreadSandbox",
463
+ tags: [OPENAPI_TAGS.agentThreads.name],
464
+ security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT,
465
+ },
466
+ }
467
+ )
426
468
  .get(
427
469
  "/api/agent-threads/:threadId/messages",
428
470
  async (context) => {
@@ -511,7 +553,7 @@ export function registerAgentRoutes(app: Elysia, host: SixbHostView) {
511
553
  summary: "Get agent message file content",
512
554
  tags: ["Agents"],
513
555
  operationId: "getAgentMessageFileContent",
514
- security: bearerSecurityRequirement("getAgentMessageFileContent"),
556
+ security: accessTokenSecurityRequirement("getAgentMessageFileContent"),
515
557
  responses: fileContentGetResponses({ optionalStorage: true }),
516
558
  },
517
559
  }
@@ -526,7 +568,7 @@ export function registerAgentRoutes(app: Elysia, host: SixbHostView) {
526
568
  summary: "Head agent message file content",
527
569
  tags: ["Agents"],
528
570
  operationId: "headAgentMessageFileContent",
529
- security: bearerSecurityRequirement("headAgentMessageFileContent"),
571
+ security: accessTokenSecurityRequirement("headAgentMessageFileContent"),
530
572
  responses: fileContentHeadResponses({ optionalStorage: true }),
531
573
  },
532
574
  }
@@ -584,7 +626,7 @@ export function registerAgentRoutes(app: Elysia, host: SixbHostView) {
584
626
  summary: "Post an agent thread message",
585
627
  tags: [OPENAPI_TAGS.agentThreads.name],
586
628
  operationId: "postAgentThreadMessage",
587
- security: SIXB_CSRF_SECURITY_REQUIREMENT,
629
+ security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT,
588
630
  },
589
631
  }
590
632
  )
@@ -679,7 +721,7 @@ export function registerAgentRoutes(app: Elysia, host: SixbHostView) {
679
721
  summary: "Cancel an agent thread's active run",
680
722
  tags: [OPENAPI_TAGS.agentRuns.name],
681
723
  operationId: "cancelAgentRun",
682
- security: SIXB_CSRF_SECURITY_REQUIREMENT,
724
+ security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT,
683
725
  },
684
726
  }
685
727
  )
@@ -734,7 +776,7 @@ export function registerAgentRoutes(app: Elysia, host: SixbHostView) {
734
776
  summary: "Retry a failed agent run",
735
777
  tags: [OPENAPI_TAGS.agentRuns.name],
736
778
  operationId: "retryAgentRun",
737
- security: SIXB_CSRF_SECURITY_REQUIREMENT,
779
+ security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT,
738
780
  },
739
781
  }
740
782
  )
@@ -10,7 +10,7 @@ import type {
10
10
  } from "@sixb/core/storage"
11
11
  import { AiLimitStorageError } from "@sixb/core/storage"
12
12
  import type { Elysia } from "elysia"
13
- import { bearerSecurityRequirement } from "../auth/access-token-boundary"
13
+ import { accessTokenSecurityRequirement } from "../auth/access-token-boundary"
14
14
  import type { RequestAuthState } from "../auth/scope"
15
15
  import { requireRequestSixb } from "../auth/scope"
16
16
  import { OPENAPI_TAGS } from "../openapi/tags"
@@ -40,6 +40,7 @@ function serializeAggregate(aggregate: AiAccountingAggregate) {
40
40
  return {
41
41
  modelCallCount: aggregate.modelCallCount,
42
42
  usage: aggregate.usage,
43
+ usageCoverage: aggregate.usageCoverage,
43
44
  costs: aggregate.costs,
44
45
  }
45
46
  }
@@ -239,7 +240,7 @@ export function registerAiAccountingRoutes(app: Elysia, host: SixbHostView) {
239
240
  summary: "Get project AI usage and cost analytics",
240
241
  tags: [OPENAPI_TAGS.aiAccounting.name],
241
242
  operationId: "getAiAccountingOverview",
242
- security: bearerSecurityRequirement("getAiAccountingOverview"),
243
+ security: accessTokenSecurityRequirement("getAiAccountingOverview"),
243
244
  },
244
245
  }
245
246
  )
@@ -287,7 +288,7 @@ export function registerAiAccountingRoutes(app: Elysia, host: SixbHostView) {
287
288
  summary: "List project AI model-call accounting records",
288
289
  tags: [OPENAPI_TAGS.aiAccounting.name],
289
290
  operationId: "listAiModelCalls",
290
- security: bearerSecurityRequirement("listAiModelCalls"),
291
+ security: accessTokenSecurityRequirement("listAiModelCalls"),
291
292
  },
292
293
  }
293
294
  )
@@ -325,7 +326,7 @@ export function registerAiAccountingRoutes(app: Elysia, host: SixbHostView) {
325
326
  summary: "List project AI usage-limit policies",
326
327
  tags: [OPENAPI_TAGS.aiAccounting.name],
327
328
  operationId: "listAiLimitPolicies",
328
- security: bearerSecurityRequirement("listAiLimitPolicies"),
329
+ security: accessTokenSecurityRequirement("listAiLimitPolicies"),
329
330
  },
330
331
  }
331
332
  )
@@ -364,7 +365,7 @@ export function registerAiAccountingRoutes(app: Elysia, host: SixbHostView) {
364
365
  summary: "Get current project AI usage-limit status",
365
366
  tags: [OPENAPI_TAGS.aiAccounting.name],
366
367
  operationId: "getAiLimitStatus",
367
- security: bearerSecurityRequirement("getAiLimitStatus"),
368
+ security: accessTokenSecurityRequirement("getAiLimitStatus"),
368
369
  },
369
370
  }
370
371
  )
@@ -394,7 +395,7 @@ export function registerAiAccountingRoutes(app: Elysia, host: SixbHostView) {
394
395
  "Lists registered groups and auth principals available for AI usage-limit policies.",
395
396
  tags: [OPENAPI_TAGS.aiAccounting.name],
396
397
  operationId: "getAiLimitSubjectOptions",
397
- security: bearerSecurityRequirement("getAiLimitSubjectOptions"),
398
+ security: accessTokenSecurityRequirement("getAiLimitSubjectOptions"),
398
399
  },
399
400
  }
400
401
  )
@@ -428,7 +429,7 @@ export function registerAiAccountingRoutes(app: Elysia, host: SixbHostView) {
428
429
  summary: "Create an AI usage-limit policy",
429
430
  tags: [OPENAPI_TAGS.aiAccounting.name],
430
431
  operationId: "createAiLimitPolicy",
431
- security: bearerSecurityRequirement("createAiLimitPolicy"),
432
+ security: accessTokenSecurityRequirement("createAiLimitPolicy"),
432
433
  },
433
434
  }
434
435
  )
@@ -466,7 +467,7 @@ export function registerAiAccountingRoutes(app: Elysia, host: SixbHostView) {
466
467
  summary: "Update an AI usage-limit policy",
467
468
  tags: [OPENAPI_TAGS.aiAccounting.name],
468
469
  operationId: "updateAiLimitPolicy",
469
- security: bearerSecurityRequirement("updateAiLimitPolicy"),
470
+ security: accessTokenSecurityRequirement("updateAiLimitPolicy"),
470
471
  },
471
472
  }
472
473
  )
@@ -504,7 +505,7 @@ export function registerAiAccountingRoutes(app: Elysia, host: SixbHostView) {
504
505
  summary: "Delete an AI usage-limit policy",
505
506
  tags: [OPENAPI_TAGS.aiAccounting.name],
506
507
  operationId: "deleteAiLimitPolicy",
507
- security: bearerSecurityRequirement("deleteAiLimitPolicy"),
508
+ security: accessTokenSecurityRequirement("deleteAiLimitPolicy"),
508
509
  },
509
510
  }
510
511
  )
@@ -548,7 +549,7 @@ export function registerAiAccountingRoutes(app: Elysia, host: SixbHostView) {
548
549
  summary: "List AI model calls grouped by initiating execution",
549
550
  tags: [OPENAPI_TAGS.aiAccounting.name],
550
551
  operationId: "listAiModelCallGroups",
551
- security: bearerSecurityRequirement("listAiModelCallGroups"),
552
+ security: accessTokenSecurityRequirement("listAiModelCallGroups"),
552
553
  },
553
554
  }
554
555
  )