@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
@@ -1,6 +1,6 @@
1
1
  import type { SixbHostView } from "@sixb/core"
2
2
  import type { Elysia } from "elysia"
3
- import { bearerSecurityRequirement } from "../auth/access-token-boundary"
3
+ import { accessTokenSecurityRequirement } from "../auth/access-token-boundary"
4
4
  import { OPENAPI_TAGS } from "../openapi/tags"
5
5
  import { ProjectInfoResponseSchema } from "../schemas/project"
6
6
  export function registerProjectRoutes(app: Elysia, host: SixbHostView) {
@@ -10,7 +10,7 @@ export function registerProjectRoutes(app: Elysia, host: SixbHostView) {
10
10
  summary: "Get current project metadata",
11
11
  tags: [OPENAPI_TAGS.project.name],
12
12
  operationId: "getProjectInfo",
13
- security: bearerSecurityRequirement("getProjectInfo"),
13
+ security: accessTokenSecurityRequirement("getProjectInfo"),
14
14
  },
15
15
  })
16
16
  }
@@ -6,7 +6,7 @@ import {
6
6
  } from "@sixb/core"
7
7
  import { ObjectNotFoundError } from "@sixb/core/storage"
8
8
  import type { Elysia } from "elysia"
9
- import { bearerSecurityRequirement } from "../auth/access-token-boundary"
9
+ import { accessTokenSecurityRequirement } from "../auth/access-token-boundary"
10
10
  import { requireRequestSixb } from "../auth/scope"
11
11
  import { OPENAPI_TAGS } from "../openapi/tags"
12
12
  import { ErrorResponseSchema } from "../schemas/common"
@@ -65,7 +65,7 @@ export function registerShareGrantRoutes(app: Elysia, _host: SixbHostView) {
65
65
  summary: "Issue a shared-access grant",
66
66
  tags: [OPENAPI_TAGS.sharedAccess.name],
67
67
  operationId: "issueSharedAccessGrant",
68
- security: bearerSecurityRequirement("issueSharedAccessGrant"),
68
+ security: accessTokenSecurityRequirement("issueSharedAccessGrant"),
69
69
  },
70
70
  }
71
71
  )
@@ -109,7 +109,7 @@ export function registerShareGrantRoutes(app: Elysia, _host: SixbHostView) {
109
109
  summary: "List shared-access grants",
110
110
  tags: [OPENAPI_TAGS.sharedAccess.name],
111
111
  operationId: "listSharedAccessGrants",
112
- security: bearerSecurityRequirement("listSharedAccessGrants"),
112
+ security: accessTokenSecurityRequirement("listSharedAccessGrants"),
113
113
  },
114
114
  }
115
115
  )
@@ -148,7 +148,7 @@ export function registerShareGrantRoutes(app: Elysia, _host: SixbHostView) {
148
148
  summary: "Revoke a shared-access grant",
149
149
  tags: [OPENAPI_TAGS.sharedAccess.name],
150
150
  operationId: "revokeSharedAccessGrant",
151
- security: bearerSecurityRequirement("revokeSharedAccessGrant"),
151
+ security: accessTokenSecurityRequirement("revokeSharedAccessGrant"),
152
152
  },
153
153
  }
154
154
  )
@@ -8,7 +8,7 @@ import {
8
8
  sharedAccessUnauthenticatedResponse,
9
9
  sharedAccessUnavailableResponse,
10
10
  } from "../auth/shared-access"
11
- import { SIXB_CSRF_SECURITY_REQUIREMENT } from "../openapi/security"
11
+ import { SIXB_CSRF_SECURITY_SCHEME_ID } from "../openapi/security"
12
12
  import { OPENAPI_TAGS } from "../openapi/tags"
13
13
  import { ErrorResponseSchema } from "../schemas/common"
14
14
  import {
@@ -112,7 +112,8 @@ export function registerSharedAccessRoutes(app: Elysia, boundary: SharedAccessBo
112
112
  summary: "Sign out a shared-access session",
113
113
  tags: [OPENAPI_TAGS.sharedAccess.name],
114
114
  operationId: "signOutSharedAccess",
115
- security: SIXB_CSRF_SECURITY_REQUIREMENT,
115
+ // Succeeds for anyone; a Share's session cookie also needs its CSRF token.
116
+ security: [{ [SIXB_CSRF_SECURITY_SCHEME_ID]: [] }, {}],
116
117
  },
117
118
  }
118
119
  )
@@ -2,7 +2,7 @@ import type { SixbHostView, SyncDefinition } from "@sixb/core"
2
2
  import type { SyncRunRecord } from "@sixb/core/storage"
3
3
  import type { Elysia } from "elysia"
4
4
  import { requireRequestSixb } from "../auth/scope"
5
- import { SIXB_CSRF_SECURITY_REQUIREMENT } from "../openapi/security"
5
+ import { SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT } from "../openapi/security"
6
6
  import { OPENAPI_TAGS } from "../openapi/tags"
7
7
  import { ErrorResponseSchema } from "../schemas/common"
8
8
  import {
@@ -210,7 +210,7 @@ export function registerSyncRoutes(app: Elysia, host: SixbHostView) {
210
210
  summary: "Request a sync run",
211
211
  tags: [OPENAPI_TAGS.syncRuns.name],
212
212
  operationId: "requestSyncRun",
213
- security: SIXB_CSRF_SECURITY_REQUIREMENT,
213
+ security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT,
214
214
  },
215
215
  }
216
216
  )
@@ -1,7 +1,7 @@
1
1
  import type { SixbHostView } from "@sixb/core"
2
2
  import type { TimeseriesPoint } from "@sixb/core/storage"
3
3
  import type { Elysia } from "elysia"
4
- import { bearerSecurityRequirement } from "../auth/access-token-boundary"
4
+ import { accessTokenSecurityRequirement } from "../auth/access-token-boundary"
5
5
  import { requireRequestSixb } from "../auth/scope"
6
6
  import { OPENAPI_TAGS } from "../openapi/tags"
7
7
  import { ErrorResponseSchema, SuccessResponseSchema } from "../schemas/common"
@@ -65,7 +65,7 @@ export function registerTelemetryRoutes(app: Elysia, _host: SixbHostView) {
65
65
  summary: "Append telemetry point",
66
66
  tags: [OPENAPI_TAGS.telemetry.name],
67
67
  operationId: "appendTelemetry",
68
- security: bearerSecurityRequirement("appendTelemetry"),
68
+ security: accessTokenSecurityRequirement("appendTelemetry"),
69
69
  },
70
70
  }
71
71
  )
@@ -106,7 +106,7 @@ export function registerTelemetryRoutes(app: Elysia, _host: SixbHostView) {
106
106
  summary: "Get bulk telemetry history",
107
107
  tags: [OPENAPI_TAGS.telemetry.name],
108
108
  operationId: "getBulkTelemetryHistory",
109
- security: bearerSecurityRequirement("getBulkTelemetryHistory"),
109
+ security: accessTokenSecurityRequirement("getBulkTelemetryHistory"),
110
110
  },
111
111
  }
112
112
  )
@@ -148,7 +148,7 @@ export function registerTelemetryRoutes(app: Elysia, _host: SixbHostView) {
148
148
  summary: "Get telemetry history",
149
149
  tags: [OPENAPI_TAGS.telemetry.name],
150
150
  operationId: "getTelemetryHistory",
151
- security: bearerSecurityRequirement("getTelemetryHistory"),
151
+ security: accessTokenSecurityRequirement("getTelemetryHistory"),
152
152
  },
153
153
  }
154
154
  )
@@ -189,7 +189,7 @@ export function registerTelemetryRoutes(app: Elysia, _host: SixbHostView) {
189
189
  summary: "Get latest telemetry point",
190
190
  tags: [OPENAPI_TAGS.telemetry.name],
191
191
  operationId: "getLatestTelemetry",
192
- security: bearerSecurityRequirement("getLatestTelemetry"),
192
+ security: accessTokenSecurityRequirement("getLatestTelemetry"),
193
193
  },
194
194
  }
195
195
  )
@@ -1,5 +1,4 @@
1
1
  import {
2
- type OntologySource,
3
2
  type Principal,
4
3
  type SixbHostView,
5
4
  SYSTEM_PRINCIPAL,
@@ -22,7 +21,7 @@ import type {
22
21
  import { AGENT_RUN_FAILURE_CODES, WORKFLOW_RUN_FAILURE_CODES } from "@sixb/core/storage"
23
22
  import type { Elysia } from "elysia"
24
23
  import { z } from "zod"
25
- import { bearerSecurityRequirement } from "../auth/access-token-boundary"
24
+ import { accessTokenSecurityRequirement } from "../auth/access-token-boundary"
26
25
  import { requestAuthState, requireRequestSixb } from "../auth/scope"
27
26
  import {
28
27
  createContextualFileContentResponse,
@@ -30,7 +29,7 @@ import {
30
29
  fileContentHeadResponses,
31
30
  handleFileContentQueryValidationError,
32
31
  } from "../files/content"
33
- import { SIXB_CSRF_SECURITY_REQUIREMENT } from "../openapi/security"
32
+ import { SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT } from "../openapi/security"
34
33
  import { OPENAPI_TAGS } from "../openapi/tags"
35
34
  import { ErrorResponseSchema } from "../schemas/common"
36
35
  import { FileContentQuerySchema } from "../schemas/files"
@@ -133,8 +132,8 @@ function serializeWorkflowNodeRun(node: WorkflowNodeRunView) {
133
132
  }
134
133
  }
135
134
 
136
- function serializePrincipal(principal: Principal) {
137
- return { principalType: principal.type, principalId: principal.id }
135
+ function serializePrincipal(principal: Principal): Principal {
136
+ return { type: principal.type, id: principal.id }
138
137
  }
139
138
 
140
139
  function serializeWorkflowAgentExecutionSummary(execution: WorkflowAgentNodeRunView) {
@@ -177,7 +176,7 @@ function isRecord(value: unknown): value is Readonly<Record<string, unknown>> {
177
176
  return value !== null && typeof value === "object" && !Array.isArray(value)
178
177
  }
179
178
 
180
- function principalForExecution(sixb: Sixb<readonly OntologySource[]>): Principal {
179
+ function principalForExecution(sixb: Sixb): Principal {
181
180
  return sixb.execution.requestedBy ?? SYSTEM_PRINCIPAL
182
181
  }
183
182
 
@@ -581,7 +580,7 @@ export function registerWorkflowRoutes(app: Elysia, host: SixbHostView) {
581
580
  summary: "List registered workflows",
582
581
  tags: [OPENAPI_TAGS.workflows.name],
583
582
  operationId: "listWorkflows",
584
- security: bearerSecurityRequirement("listWorkflows"),
583
+ security: accessTokenSecurityRequirement("listWorkflows"),
585
584
  },
586
585
  }
587
586
  )
@@ -607,7 +606,7 @@ export function registerWorkflowRoutes(app: Elysia, host: SixbHostView) {
607
606
  summary: "Get workflow metadata",
608
607
  tags: [OPENAPI_TAGS.workflows.name],
609
608
  operationId: "getWorkflow",
610
- security: bearerSecurityRequirement("getWorkflow"),
609
+ security: accessTokenSecurityRequirement("getWorkflow"),
611
610
  },
612
611
  }
613
612
  )
@@ -777,7 +776,7 @@ export function registerWorkflowRoutes(app: Elysia, host: SixbHostView) {
777
776
  summary: "Submit a workflow intervention response",
778
777
  tags: [OPENAPI_TAGS.workflowInterventions.name],
779
778
  operationId: "submitWorkflowIntervention",
780
- security: SIXB_CSRF_SECURITY_REQUIREMENT,
779
+ security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT,
781
780
  },
782
781
  }
783
782
  )
@@ -905,7 +904,7 @@ export function registerWorkflowRoutes(app: Elysia, host: SixbHostView) {
905
904
  summary: "Cancel a workflow intervention",
906
905
  tags: [OPENAPI_TAGS.workflowInterventions.name],
907
906
  operationId: "cancelWorkflowIntervention",
908
- security: SIXB_CSRF_SECURITY_REQUIREMENT,
907
+ security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT,
909
908
  },
910
909
  }
911
910
  )
@@ -953,7 +952,7 @@ export function registerWorkflowRoutes(app: Elysia, host: SixbHostView) {
953
952
  summary: "List workflow run history",
954
953
  tags: [OPENAPI_TAGS.workflowRuns.name],
955
954
  operationId: "listWorkflowRuns",
956
- security: bearerSecurityRequirement("listWorkflowRuns"),
955
+ security: accessTokenSecurityRequirement("listWorkflowRuns"),
957
956
  },
958
957
  }
959
958
  )
@@ -1008,7 +1007,7 @@ export function registerWorkflowRoutes(app: Elysia, host: SixbHostView) {
1008
1007
  summary: "Get workflow run detail",
1009
1008
  tags: [OPENAPI_TAGS.workflowRuns.name],
1010
1009
  operationId: "getWorkflowRun",
1011
- security: bearerSecurityRequirement("getWorkflowRun"),
1010
+ security: accessTokenSecurityRequirement("getWorkflowRun"),
1012
1011
  },
1013
1012
  }
1014
1013
  )
@@ -1055,7 +1054,7 @@ export function registerWorkflowRoutes(app: Elysia, host: SixbHostView) {
1055
1054
  summary: "Get workflow agent node execution detail",
1056
1055
  tags: [OPENAPI_TAGS.workflowRuns.name],
1057
1056
  operationId: "getWorkflowAgentNodeExecution",
1058
- security: bearerSecurityRequirement("getWorkflowAgentNodeExecution"),
1057
+ security: accessTokenSecurityRequirement("getWorkflowAgentNodeExecution"),
1059
1058
  },
1060
1059
  }
1061
1060
  )
@@ -1230,7 +1229,7 @@ export function registerWorkflowRoutes(app: Elysia, host: SixbHostView) {
1230
1229
  summary: "Cancel a workflow run",
1231
1230
  tags: [OPENAPI_TAGS.workflowRuns.name],
1232
1231
  operationId: "cancelWorkflowRun",
1233
- security: bearerSecurityRequirement("cancelWorkflowRun"),
1232
+ security: accessTokenSecurityRequirement("cancelWorkflowRun"),
1234
1233
  },
1235
1234
  }
1236
1235
  )
@@ -1245,7 +1244,7 @@ export function registerWorkflowRoutes(app: Elysia, host: SixbHostView) {
1245
1244
  summary: "Get workflow run file content",
1246
1245
  tags: ["Workflows"],
1247
1246
  operationId: "getWorkflowRunFileContent",
1248
- security: bearerSecurityRequirement("getWorkflowRunFileContent"),
1247
+ security: accessTokenSecurityRequirement("getWorkflowRunFileContent"),
1249
1248
  responses: fileContentGetResponses({ optionalStorage: true }),
1250
1249
  },
1251
1250
  }
@@ -1261,7 +1260,7 @@ export function registerWorkflowRoutes(app: Elysia, host: SixbHostView) {
1261
1260
  summary: "Head workflow run file content",
1262
1261
  tags: ["Workflows"],
1263
1262
  operationId: "headWorkflowRunFileContent",
1264
- security: bearerSecurityRequirement("headWorkflowRunFileContent"),
1263
+ security: accessTokenSecurityRequirement("headWorkflowRunFileContent"),
1265
1264
  responses: fileContentHeadResponses({ optionalStorage: true }),
1266
1265
  },
1267
1266
  }
@@ -1277,7 +1276,7 @@ export function registerWorkflowRoutes(app: Elysia, host: SixbHostView) {
1277
1276
  summary: "Get workflow node run file content",
1278
1277
  tags: ["Workflows"],
1279
1278
  operationId: "getWorkflowNodeRunFileContent",
1280
- security: bearerSecurityRequirement("getWorkflowNodeRunFileContent"),
1279
+ security: accessTokenSecurityRequirement("getWorkflowNodeRunFileContent"),
1281
1280
  responses: fileContentGetResponses({ optionalStorage: true }),
1282
1281
  },
1283
1282
  }
@@ -1293,7 +1292,7 @@ export function registerWorkflowRoutes(app: Elysia, host: SixbHostView) {
1293
1292
  summary: "Head workflow node run file content",
1294
1293
  tags: ["Workflows"],
1295
1294
  operationId: "headWorkflowNodeRunFileContent",
1296
- security: bearerSecurityRequirement("headWorkflowNodeRunFileContent"),
1295
+ security: accessTokenSecurityRequirement("headWorkflowNodeRunFileContent"),
1297
1296
  responses: fileContentHeadResponses({ optionalStorage: true }),
1298
1297
  },
1299
1298
  }
@@ -1341,7 +1340,7 @@ export function registerWorkflowRoutes(app: Elysia, host: SixbHostView) {
1341
1340
  summary: "Request a workflow run",
1342
1341
  tags: [OPENAPI_TAGS.workflowRuns.name],
1343
1342
  operationId: "requestWorkflowRun",
1344
- security: bearerSecurityRequirement("requestWorkflowRun"),
1343
+ security: accessTokenSecurityRequirement("requestWorkflowRun"),
1345
1344
  },
1346
1345
  }
1347
1346
  )
@@ -1,4 +1,3 @@
1
- import type { OntologySource } from "@sixb/core"
2
1
  import {
3
2
  AGENT_ACTIVITY_STREAM_ID,
4
3
  type AgentRunActivityEvent,
@@ -81,7 +80,7 @@ export function parseAgentStreamMessage(payload: unknown):
81
80
  }
82
81
 
83
82
  export async function canAccessAgentRunStream(
84
- sixb: Sixb<readonly OntologySource[]>,
83
+ sixb: Sixb,
85
84
  runId: string
86
85
  ): Promise<{ ok: true } | { ok: false; message: string }> {
87
86
  const run = await sixb.agent.runs.getById(runId)
@@ -92,7 +91,7 @@ export async function canAccessAgentRunStream(
92
91
  }
93
92
 
94
93
  export async function canAccessAgentThreadActivity(
95
- sixb: Sixb<readonly OntologySource[]>,
94
+ sixb: Sixb,
96
95
  event: AgentRunActivityEvent
97
96
  ): Promise<boolean> {
98
97
  const run = await sixb.agent.runs.getById(event.runId)
@@ -308,7 +307,7 @@ async function subscribeAgentActivity(
308
307
  }
309
308
 
310
309
  async function sendVisibleActivityRecords(
311
- sixb: Sixb<readonly OntologySource[]>,
310
+ sixb: Sixb,
312
311
  ws: { send: (message: string) => void },
313
312
  records: readonly BrokerRecord[]
314
313
  ): Promise<void> {
@@ -398,7 +397,7 @@ function stopSubscription(state: AgentStreamSubscriptionState | undefined): void
398
397
  }
399
398
 
400
399
  async function sendRunSnapshot(
401
- sixb: Sixb<readonly OntologySource[]>,
400
+ sixb: Sixb,
402
401
  ws: { send: (message: string) => void },
403
402
  runId: string
404
403
  ): Promise<boolean> {
@@ -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
 
@@ -33,18 +33,21 @@ export const AuthInvitationDeliverySchema = z.object({
33
33
  export const AuthInvitationGroupOptionSchema = AuthGroupOptionSchema
34
34
 
35
35
  export const AuthAccessTokenKindSchema = z.enum(["personal", "serviceAccount"])
36
- export const AuthAccessTokenSubjectTypeSchema = z.enum(["user", "serviceAccount"])
37
36
  export const AuthAccessTokenStatusSchema = z.enum(["active", "expired", "revoked"])
38
37
  export const AuthServiceAccountStatusSchema = z.enum(["active", "suspended"])
39
38
  export const AuthUserStatusSchema = z.enum(["active", "suspended"])
40
39
 
40
+ export const AuthAccessTokenSubjectSchema = z.object({
41
+ type: z.enum(["user", "serviceAccount"]),
42
+ id: z.string(),
43
+ })
44
+
41
45
  export const AuthAccessTokenSchema = z.object({
42
46
  id: z.string(),
43
47
  name: z.string(),
44
48
  kind: AuthAccessTokenKindSchema,
45
49
  status: AuthAccessTokenStatusSchema,
46
- subjectType: AuthAccessTokenSubjectTypeSchema,
47
- subjectId: z.string(),
50
+ subject: AuthAccessTokenSubjectSchema,
48
51
  subjectLabel: z.string().optional(),
49
52
  groupIds: z.array(z.string()).optional(),
50
53
  createdAt: z.string(),
@@ -272,7 +275,9 @@ export const AuthSessionResponseSchema = z.union([
272
275
  }),
273
276
  z.object({
274
277
  authenticated: z.literal(true),
275
- csrfToken: z.string(),
278
+ /** Browser sessions only: send it back in `x-sixb-csrf` on mutations. */
279
+ csrfToken: z.string().optional(),
280
+ /** Whether the user may open a web app: the browser session's own, or Atlas for a native client. */
276
281
  applicationAccess: z.object({
277
282
  allowed: z.boolean(),
278
283
  audience: z.enum(["atlas", "app"]),
@@ -296,9 +301,20 @@ export const AuthSignOutResponseSchema = z.object({
296
301
  })
297
302
 
298
303
  export const CreateDeviceAuthorizationBodySchema = z.object({
304
+ /** Shown to the approving user and on their sessions list, such as "sixb CLI on alex-mbp". */
299
305
  clientName: z.string().trim().min(1).max(100),
300
- tokenName: z.string().trim().min(1).max(100),
301
- expiresIn: z.literal("90d").optional(),
306
+ })
307
+
308
+ /** A native client's session tokens. Send `accessToken` as a Bearer token until `expiresIn` runs out. */
309
+ export const BearerSessionTokensSchema = z.object({
310
+ accessToken: z.string(),
311
+ refreshToken: z.string(),
312
+ /** Seconds until the access token expires. */
313
+ expiresIn: z.number(),
314
+ })
315
+
316
+ export const RefreshAuthSessionBodySchema = z.object({
317
+ refreshToken: z.string().min(1),
302
318
  })
303
319
 
304
320
  export const CreateDeviceAuthorizationResponseSchema = z.object({
@@ -318,7 +334,7 @@ export const ExchangeDeviceAuthorizationResponseSchema = z.union([
318
334
  z.object({ status: z.literal("pending") }),
319
335
  z.object({ status: z.literal("denied") }),
320
336
  z.object({ status: z.literal("expired") }),
321
- z.object({ status: z.literal("approved"), accessToken: z.string() }),
337
+ BearerSessionTokensSchema.extend({ status: z.literal("approved") }),
322
338
  ])
323
339
 
324
340
  export const DeviceAuthorizationDecisionBodySchema = z.object({
@@ -329,13 +345,16 @@ export const DeviceAuthorizationDecisionBodySchema = z.object({
329
345
 
330
346
  export const AuthSessionSummarySchema = z.object({
331
347
  id: z.string(),
332
- audience: z.enum(["atlas", "app"]),
348
+ /** The web app a browser session belongs to. Native clients' sessions have none. */
349
+ audience: z.enum(["atlas", "app"]).optional(),
333
350
  current: z.boolean(),
334
351
  createdAt: z.string(),
335
352
  expiresAt: z.string(),
336
353
  lastSeenAt: z.string().optional(),
337
354
  userAgent: z.string().optional(),
338
355
  ipAddress: z.string().optional(),
356
+ /** Set for native clients, such as the CLI. */
357
+ clientName: z.string().optional(),
339
358
  })
340
359
 
341
360
  export const ListAuthSessionsResponseSchema = z.object({
@@ -15,6 +15,12 @@ export function codedErrorResponseSchema<
15
15
 
16
16
  export const SuccessResponseSchema = z.object({ success: z.boolean() })
17
17
 
18
+ /** The canonical `Principal` shape from `@sixb/core`. */
19
+ export const PrincipalSchema = z.object({
20
+ type: z.enum(["user", "serviceAccount", "system"]),
21
+ id: z.string().min(1),
22
+ })
23
+
18
24
  export type JsonValue =
19
25
  | string
20
26
  | number
@@ -84,3 +90,8 @@ export const jsonValueOpenApiOverride: OverrideCallback = (def) => {
84
90
 
85
91
  return ignoreOverride
86
92
  }
93
+
94
+ export const AiUsageLimitErrorResponseSchema = codedErrorResponseSchema([
95
+ "ai.usage_limit_exceeded",
96
+ "ai.usage_limit_unavailable",
97
+ ]).extend({ details: JsonValueSchema.optional() })
@@ -1,4 +1,4 @@
1
- import type { DomainEvent } from "@sixb/core"
1
+ import type { DomainEvent, TrustedPrimitiveKind } from "@sixb/core"
2
2
  import {
3
3
  EVENT_TOPICS as CORE_EVENT_TOPICS,
4
4
  EVENT_TYPES as CORE_EVENT_TYPES,
@@ -60,15 +60,38 @@ const StoredEventBaseSchema = z.object({
60
60
  schemaVersion: z.literal(1),
61
61
  projectId: z.string(),
62
62
  occurredAt: z.string(),
63
- actor: z
64
- .object({
65
- type: z.enum(["user", "serviceAccount", "system"]),
66
- id: z.string(),
67
- })
68
- .optional(),
69
63
  partitionKey: z.string(),
70
64
  })
71
65
 
66
+ const TRUSTED_PRIMITIVE_KINDS = [
67
+ "action",
68
+ "pipeline",
69
+ "projection",
70
+ "rule",
71
+ "sync",
72
+ "webhook",
73
+ "workflow",
74
+ ] as const satisfies readonly TrustedPrimitiveKind[]
75
+
76
+ /** Mirrors the core `EventExecutor`: the workload that made an ontology change. */
77
+ export const EventExecutorSchema = z.discriminatedUnion("type", [
78
+ z.object({ type: z.literal("request"), requestId: z.string() }),
79
+ z.object({
80
+ type: z.literal("primitive"),
81
+ kind: z.enum(TRUSTED_PRIMITIVE_KINDS),
82
+ id: z.string(),
83
+ runId: z.string(),
84
+ }),
85
+ z.object({ type: z.literal("agent"), runId: z.string() }),
86
+ z.object({
87
+ type: z.literal("kernel"),
88
+ operation: z.discriminatedUnion("type", [
89
+ z.object({ type: z.literal("ontology.recover"), recoveryId: z.string() }),
90
+ z.object({ type: z.literal("ontology.indexVectors"), indexingId: z.string() }),
91
+ ]),
92
+ }),
93
+ ])
94
+
72
95
  const StoredAuthorableEventBaseSchema = StoredEventBaseSchema.extend({
73
96
  correlationId: z.string().optional(),
74
97
  causationId: z.string().optional(),
@@ -79,6 +102,11 @@ const StoredAuthorableEventBaseSchema = StoredEventBaseSchema.extend({
79
102
 
80
103
  const StoredOntologyEventBaseSchema = StoredEventBaseSchema.extend({
81
104
  origin: EventOriginSchema,
105
+ requestedBy: z
106
+ .object({ type: z.enum(["user", "serviceAccount"]), id: z.string() })
107
+ .optional()
108
+ .describe("Principal on whose behalf the write ran; absent for automatic or anonymous work."),
109
+ executor: EventExecutorSchema,
82
110
  commitId: z.string(),
83
111
  commitOrdinal: z.number().int().nonnegative(),
84
112
  })
@@ -1,6 +1,11 @@
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
10
  type OpenApiSchema = NonNullable<
6
11
  NonNullable<NonNullable<ElysiaOpenAPIConfig["documentation"]>["components"]>["schemas"]
@@ -229,8 +234,8 @@ export const ObjectQuerySchema: z.ZodType<unknown> = z.lazy(() =>
229
234
  .object({
230
235
  kind: z.literal("vector"),
231
236
  input: ObjectQuerySchema,
232
- vector: z.array(z.number().finite()),
233
- propertyId: z.string().min(1),
237
+ vector: z.string().min(1).max(8000),
238
+ profile: z.string().min(1),
234
239
  k: z.number().int().positive(),
235
240
  })
236
241
  .strict(),
@@ -334,6 +339,7 @@ export const ObjectQueryLinksRequestSchema = z
334
339
  .strict()
335
340
 
336
341
  export const TwinObjectSchema = z.object({
342
+ score: z.number().finite().optional(),
337
343
  primaryId: z.string(),
338
344
  objectTypeId: z.string(),
339
345
  properties: z.record(z.unknown()),
@@ -377,6 +383,7 @@ export const ObjectQueryOpenApiSchemas: OpenApiSchemas = {
377
383
  required: ["primaryId", "objectTypeId", "properties", "createdAt", "updatedAt"],
378
384
  additionalProperties: false,
379
385
  properties: {
386
+ score: { type: "number" },
380
387
  primaryId: { type: "string" },
381
388
  objectTypeId: { type: "string" },
382
389
  properties: { type: "object", additionalProperties: true },
@@ -540,6 +547,11 @@ export const ObjectQueryOpenApiSchemas: OpenApiSchemas = {
540
547
  nextPageToken: { type: "string" },
541
548
  },
542
549
  },
550
+ AiUsageLimitErrorResponse: zodToJsonSchema(AiUsageLimitErrorResponseSchema, {
551
+ target: "openApi3",
552
+ $refStrategy: "none",
553
+ override: jsonValueOpenApiOverride,
554
+ }) as OpenApi3Schema,
543
555
  ObjectQueryErrorResponse: {
544
556
  type: "object",
545
557
  required: ["error"],
@@ -680,13 +692,13 @@ export const ObjectQueryOpenApiSchemas: OpenApiSchemas = {
680
692
  },
681
693
  {
682
694
  type: "object",
683
- required: ["kind", "input", "vector", "propertyId", "k"],
695
+ required: ["kind", "input", "vector", "profile", "k"],
684
696
  additionalProperties: false,
685
697
  properties: {
686
698
  kind: { type: "string", enum: ["vector"] },
687
699
  input: objectQueryRef,
688
- vector: { type: "array", items: { type: "number" } },
689
- propertyId: { type: "string", minLength: 1 },
700
+ vector: { type: "string", minLength: 1, maxLength: 8000 },
701
+ profile: { type: "string", minLength: 1 },
690
702
  k: { type: "integer", minimum: 1 },
691
703
  },
692
704
  },