@sixb/server 0.1.25 → 0.1.26

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 (67) hide show
  1. package/dist/auth/public-routes.d.ts.map +1 -1
  2. package/dist/auth/run-token.d.ts +28 -0
  3. package/dist/auth/run-token.d.ts.map +1 -0
  4. package/dist/auth/scope.d.ts +11 -13
  5. package/dist/auth/scope.d.ts.map +1 -1
  6. package/dist/index.js +3240 -3042
  7. package/dist/index.js.map +29 -27
  8. package/dist/registerRoutes.d.ts.map +1 -1
  9. package/dist/routes/agent-approval-gate.d.ts +7 -4
  10. package/dist/routes/agent-approval-gate.d.ts.map +1 -1
  11. package/dist/routes/agent-approvals.d.ts +4 -1
  12. package/dist/routes/agent-approvals.d.ts.map +1 -1
  13. package/dist/routes/agent-computers.d.ts +134 -0
  14. package/dist/routes/agent-computers.d.ts.map +1 -0
  15. package/dist/routes/agent-runners.d.ts +74 -0
  16. package/dist/routes/agent-runners.d.ts.map +1 -0
  17. package/dist/routes/agents.d.ts +28 -0
  18. package/dist/routes/agents.d.ts.map +1 -1
  19. package/dist/routes/artifacts.d.ts +5 -28
  20. package/dist/routes/artifacts.d.ts.map +1 -1
  21. package/dist/routes/auth.d.ts +1 -1
  22. package/dist/routes/datasets.d.ts.map +1 -1
  23. package/dist/routes/observed-agent-threads.d.ts +3 -0
  24. package/dist/routes/observed-agent-threads.d.ts.map +1 -1
  25. package/dist/routes/pipelines.d.ts.map +1 -1
  26. package/dist/routes/projections.d.ts +2 -0
  27. package/dist/routes/projections.d.ts.map +1 -1
  28. package/dist/routes/shared-access.d.ts +2 -2
  29. package/dist/routes/syncs.d.ts +34 -34
  30. package/dist/routes/syncs.d.ts.map +1 -1
  31. package/dist/routes/users.d.ts +1 -0
  32. package/dist/routes/users.d.ts.map +1 -1
  33. package/dist/routes/workflows.d.ts +4 -4
  34. package/dist/schemas/agents.d.ts +79 -1
  35. package/dist/schemas/agents.d.ts.map +1 -1
  36. package/dist/schemas/auth.d.ts +2 -2
  37. package/dist/schemas/projections.d.ts +14 -0
  38. package/dist/schemas/projections.d.ts.map +1 -1
  39. package/dist/schemas/shared-access.d.ts +2 -2
  40. package/dist/schemas/syncs.d.ts +24 -24
  41. package/dist/schemas/users.d.ts +8 -0
  42. package/dist/schemas/users.d.ts.map +1 -1
  43. package/dist/server.d.ts +1 -0
  44. package/dist/server.d.ts.map +1 -1
  45. package/package.json +5 -5
  46. package/src/auth/public-routes.ts +0 -6
  47. package/src/auth/run-token.ts +327 -0
  48. package/src/auth/scope.ts +16 -37
  49. package/src/registerRoutes.ts +4 -2
  50. package/src/routes/agent-approval-gate.ts +40 -14
  51. package/src/routes/agent-approvals.ts +1 -1
  52. package/src/routes/agent-computers.ts +126 -0
  53. package/src/routes/agent-runners.ts +181 -0
  54. package/src/routes/agents.ts +7 -2
  55. package/src/routes/artifacts.ts +55 -11
  56. package/src/routes/datasets.ts +5 -0
  57. package/src/routes/pipelines.ts +5 -0
  58. package/src/routes/syncs.ts +4 -0
  59. package/src/routes/users.ts +15 -2
  60. package/src/schemas/agents.ts +16 -1
  61. package/src/schemas/artifacts.ts +1 -1
  62. package/src/schemas/projections.ts +2 -0
  63. package/src/schemas/users.ts +6 -0
  64. package/src/server.ts +35 -13
  65. package/dist/routes/agent-api-gateway.d.ts +0 -4
  66. package/dist/routes/agent-api-gateway.d.ts.map +0 -1
  67. package/src/routes/agent-api-gateway.ts +0 -404
@@ -1,6 +1,7 @@
1
1
  import type { PipelineDefinition, PipelineStepExecutor, SixbHostView } from "@sixb/core"
2
2
  import type { PipelineRunRecord, PipelineStepRunRecord } from "@sixb/core/storage"
3
3
  import type { Elysia } from "elysia"
4
+ import { accessTokenSecurityRequirement } from "../auth/access-token-boundary"
4
5
  import { requireRequestSixb } from "../auth/scope"
5
6
  import { SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT } from "../openapi/security"
6
7
  import { OPENAPI_TAGS } from "../openapi/tags"
@@ -143,6 +144,7 @@ export function registerPipelineRoutes(app: Elysia, host: SixbHostView) {
143
144
  summary: "List registered pipelines",
144
145
  tags: [OPENAPI_TAGS.pipelines.name],
145
146
  operationId: "listPipelines",
147
+ security: accessTokenSecurityRequirement("listPipelines"),
146
148
  },
147
149
  }
148
150
  )
@@ -166,6 +168,7 @@ export function registerPipelineRoutes(app: Elysia, host: SixbHostView) {
166
168
  summary: "Get pipeline metadata",
167
169
  tags: [OPENAPI_TAGS.pipelines.name],
168
170
  operationId: "getPipeline",
171
+ security: accessTokenSecurityRequirement("getPipeline"),
169
172
  },
170
173
  }
171
174
  )
@@ -211,6 +214,7 @@ export function registerPipelineRoutes(app: Elysia, host: SixbHostView) {
211
214
  summary: "List pipeline run history",
212
215
  tags: [OPENAPI_TAGS.pipelineRuns.name],
213
216
  operationId: "listPipelineRuns",
217
+ security: accessTokenSecurityRequirement("listPipelineRuns"),
214
218
  },
215
219
  }
216
220
  )
@@ -257,6 +261,7 @@ export function registerPipelineRoutes(app: Elysia, host: SixbHostView) {
257
261
  summary: "Get pipeline run detail",
258
262
  tags: [OPENAPI_TAGS.pipelineRuns.name],
259
263
  operationId: "getPipelineRun",
264
+ security: accessTokenSecurityRequirement("getPipelineRun"),
260
265
  },
261
266
  }
262
267
  )
@@ -1,6 +1,7 @@
1
1
  import type { SixbHostView, SyncDefinition } from "@sixb/core"
2
2
  import type { SyncRunRecord } from "@sixb/core/storage"
3
3
  import type { Elysia } from "elysia"
4
+ import { accessTokenSecurityRequirement } from "../auth/access-token-boundary"
4
5
  import { requireRequestSixb } from "../auth/scope"
5
6
  import { SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT } from "../openapi/security"
6
7
  import { OPENAPI_TAGS } from "../openapi/tags"
@@ -105,6 +106,7 @@ export function registerSyncRoutes(app: Elysia, host: SixbHostView) {
105
106
  summary: "List registered syncs",
106
107
  tags: [OPENAPI_TAGS.syncs.name],
107
108
  operationId: "listSyncs",
109
+ security: accessTokenSecurityRequirement("listSyncs"),
108
110
  },
109
111
  }
110
112
  )
@@ -128,6 +130,7 @@ export function registerSyncRoutes(app: Elysia, host: SixbHostView) {
128
130
  summary: "Get sync metadata",
129
131
  tags: [OPENAPI_TAGS.syncs.name],
130
132
  operationId: "getSync",
133
+ security: accessTokenSecurityRequirement("getSync"),
131
134
  },
132
135
  }
133
136
  )
@@ -174,6 +177,7 @@ export function registerSyncRoutes(app: Elysia, host: SixbHostView) {
174
177
  summary: "List sync run history",
175
178
  tags: [OPENAPI_TAGS.syncRuns.name],
176
179
  operationId: "listSyncRuns",
180
+ security: accessTokenSecurityRequirement("listSyncRuns"),
177
181
  },
178
182
  }
179
183
  )
@@ -17,8 +17,21 @@ export function registerUserRoutes(app: Elysia, _host: SixbHostView) {
17
17
  const sixb = requireRequestSixb(context)
18
18
 
19
19
  try {
20
- const page = await sixb.users.list(ListUsersQuerySchema.parse(query))
21
- return { users: [...page.users], hasMore: page.hasMore, total: page.total }
20
+ const { email, ...input } = ListUsersQuerySchema.parse(query)
21
+ if (email === undefined) {
22
+ const page = await sixb.users.list(input)
23
+ return { users: [...page.users], hasMore: page.hasMore, total: page.total }
24
+ }
25
+
26
+ // `users.get({ email })` over HTTP: a query parameter, so an email never goes in a path.
27
+ if (Object.values(input).some((value) => value !== undefined)) {
28
+ set.status = 400
29
+ return {
30
+ error: "[SixbServer] email finds one member and takes no other option.",
31
+ }
32
+ }
33
+ const profile = await sixb.users.get({ email })
34
+ return { users: profile ? [profile] : [], hasMore: false, total: profile ? 1 : 0 }
22
35
  } catch (error) {
23
36
  return handleRouteError(error, set)
24
37
  }
@@ -109,6 +109,8 @@ export const CreateAgentThreadBodySchema = z
109
109
  title: z.string().trim().min(1).optional(),
110
110
  threadId: z.string().trim().min(1).optional(),
111
111
  sandbox: z.record(z.string(), JsonValueSchema).optional(),
112
+ /** Run its turns on your computer, which claims them, instead of in the cloud. */
113
+ runsOn: z.literal("computer").optional(),
112
114
  })
113
115
  .strict()
114
116
 
@@ -151,6 +153,10 @@ export const AgentThreadSchema = z.object({
151
153
  participants: z.array(AgentThreadParticipantSchema),
152
154
  title: z.string().optional(),
153
155
  sandboxParams: z.record(z.string(), JsonValueSchema).optional(),
156
+ /** Its turns run on its owner's computer; absent, in the cloud. */
157
+ runsOn: z.literal("computer").optional(),
158
+ /** Which of its owner's computers runs it; absent until one claims its first turn. */
159
+ computerId: z.string().optional(),
154
160
  status: AgentThreadStatusSchema,
155
161
  activeRunId: z.string().nullable(),
156
162
  lastMessageAt: z.string().optional(),
@@ -176,6 +182,13 @@ export const CreateAgentThreadResponseSchema = z.object({
176
182
  thread: AgentThreadSchema,
177
183
  })
178
184
 
185
+ export const MoveAgentThreadToComputerBodySchema = z
186
+ .object({
187
+ /** The id `sixb` keeps for the computer, beside its sign-in. */
188
+ computerId: z.string().trim().min(1).max(200),
189
+ })
190
+ .strict()
191
+
179
192
  export const AddAgentThreadParticipantsBodySchema = z
180
193
  .object({
181
194
  /**
@@ -349,7 +362,7 @@ export const AgentMessageListResponseSchema = z.object({
349
362
 
350
363
  export const PostAgentMessageBodySchema = z
351
364
  .object({
352
- /** Required unless `continue` is set. */
365
+ /** Required unless `continue` is set or `attachments` are the whole message. */
353
366
  text: z.string().trim().min(1).optional(),
354
367
  /** Continue the previous answer after it reached the turn limit, without text of its own. */
355
368
  continue: z.literal(true).optional(),
@@ -403,6 +416,8 @@ export const AgentRunSchema = z.object({
403
416
  reasoning: ModelReasoningSchema.optional(),
404
417
  /** What the turn could change without asking. Absent on turns from before approval modes. */
405
418
  approvalMode: AgentApprovalModeSchema.optional(),
419
+ /** Its owner's computer claims it; absent, the cloud runs it. */
420
+ runsOn: z.literal("computer").optional(),
406
421
  modelId: z.string().optional(),
407
422
  /**
408
423
  * `awaiting_approval`: the turn succeeded and paused on calls waiting for its requester. It stays
@@ -237,7 +237,7 @@ export const ArtifactErrorResponseSchema = ErrorResponseSchema.extend({
237
237
  .string()
238
238
  .optional()
239
239
  .describe(
240
- "Stable machine-readable failure code: artifact_not_found, artifact_kind_mismatch, artifact_moved, invalid_artifact, invalid_state, state_full, not_allowed, not_shared (it exists but no conversation you read shares it), read_only (you observe the conversation that shares it), query_not_found, query_invalid (the ontology no longer admits the query), or storage_unavailable."
240
+ "Stable machine-readable failure code: artifact_not_found, artifact_kind_mismatch, artifact_moved, invalid_artifact, invalid_state, state_full, not_allowed, not_shared (it exists but no conversation you read shares it), read_only (you observe the conversation that shares it), query_not_found, query_invalid (the ontology no longer admits the query), execution_lost (a run token's run ended or moved to another runner), or storage_unavailable."
241
241
  ),
242
242
  latest: z
243
243
  .object({ version: z.number().int(), author: PrincipalSchema })
@@ -96,6 +96,8 @@ export const ObjectProjectionSchema = z.object({
96
96
  objectTypeId: z.string(),
97
97
  datasetId: z.string(),
98
98
  properties: z.record(z.string()),
99
+ /** The `ref.user()` properties whose column holds a member's email. */
100
+ users: z.record(z.literal("email")).optional(),
99
101
  links: z.record(ForeignKeyDescriptorSchema),
100
102
  conflictResolution: SourceEditConflictResolutionSchema,
101
103
  latestRun: ProjectionRunSchema.nullable(),
@@ -3,6 +3,7 @@ import { UserProfileSchema } from "./auth"
3
3
 
4
4
  export const MAX_USERS_PAGE_LIMIT = 200
5
5
  export const MAX_USERS_SEARCH_LENGTH = 200
6
+ export const MAX_USER_EMAIL_LENGTH = 320
6
7
 
7
8
  export const ListUsersQuerySchema = z.object({
8
9
  /** Which members to list. Defaults to `active`. */
@@ -11,6 +12,11 @@ export const ListUsersQuerySchema = z.object({
11
12
  search: z.string().max(MAX_USERS_SEARCH_LENGTH).optional(),
12
13
  limit: z.coerce.number().int().min(1).max(MAX_USERS_PAGE_LIMIT).optional(),
13
14
  offset: z.coerce.number().int().min(0).optional(),
15
+ /**
16
+ * The member with exactly this email, ignoring case, suspended or not: a page of at most one.
17
+ * Takes no other option.
18
+ */
19
+ email: z.string().min(1).max(MAX_USER_EMAIL_LENGTH).optional(),
14
20
  })
15
21
 
16
22
  export const ListUsersResponseSchema = z.object({
package/src/server.ts CHANGED
@@ -1,7 +1,7 @@
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 { bindAgentGatewayRequestExecution } from "@sixb/core/internal/agent-execution"
4
+ import { bindAgentRunRequestExecution } from "@sixb/core/internal/agent-execution"
5
5
  import { ARTIFACT_FRAME_ROUTE_PREFIX } from "@sixb/core/internal/artifacts/frames"
6
6
  import { CSRF_HEADER_NAME, setRequestClientAddress } from "@sixb/core/internal/auth"
7
7
  import { bindRequestExecution } from "@sixb/core/internal/request-execution"
@@ -33,7 +33,7 @@ import {
33
33
  import { CSRF_TOKEN_RESPONSE_HEADER_NAME } from "./auth/csrf"
34
34
  import type { SixbAuthExperienceOptions } from "./auth/experience"
35
35
  import { ServerAuthGuard } from "./auth/guard"
36
- import { consumeInternalRequestAuthState } from "./auth/scope"
36
+ import { type RunTokenDecision, requestRunToken, resolveRunTokenRequest } from "./auth/run-token"
37
37
  import { SESSION_ACTIVITY_HEADER_NAME } from "./auth/session-activity"
38
38
  import { createSessionRenewalCookieHeaders } from "./auth/session-cookies"
39
39
  import {
@@ -55,6 +55,7 @@ import {
55
55
  } from "./openapi/security"
56
56
  import { OPENAPI_TAG_METADATA } from "./openapi/tags"
57
57
  import { registerHttpRoutes } from "./registerRoutes"
58
+ import { agentRunSessionHandler, startLapsedRunSweeper } from "./routes/agent-runners"
58
59
  import { registerAuthRoutes } from "./routes/auth"
59
60
  import { DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES } from "./routes/files"
60
61
  import { registerWebhookRoutes } from "./routes/webhooks"
@@ -100,6 +101,7 @@ export class SixbServer {
100
101
  private app: SixbApp | null = null
101
102
  private bunServer: ReturnType<typeof Bun.serve> | null = null
102
103
  private maintenance: OntologyMaintenanceHandle | null = null
104
+ private stopSweeper: (() => void) | null = null
103
105
 
104
106
  constructor(options: SixbServerOptions) {
105
107
  this.hostRuntime = options.host
@@ -199,6 +201,9 @@ export class SixbServer {
199
201
  throw new Error(`[SixbServer] Failed to listen on ${this.hostname}:${this.port}: ${message}`)
200
202
  }
201
203
 
204
+ // A runner on a computer has no worker behind it: the API ends the runs it stops renewing.
205
+ this.stopSweeper = startLapsedRunSweeper(this.hostRuntime)
206
+
202
207
  if (!this.quiet) {
203
208
  const base = `http://${this.hostname}:${this.getPort()}`
204
209
  console.log(`Sixb server running at ${base}`)
@@ -207,6 +212,8 @@ export class SixbServer {
207
212
  }
208
213
 
209
214
  async stop(): Promise<void> {
215
+ this.stopSweeper?.()
216
+ this.stopSweeper = null
210
217
  if (this.bunServer) {
211
218
  this.bunServer.stop(true)
212
219
  this.bunServer = null
@@ -234,6 +241,7 @@ export function createSixbApi(server: SixbServer) {
234
241
  Request,
235
242
  Awaited<ReturnType<SharedAccessBoundary["resolveRequest"]>>
236
243
  >()
244
+ const preparedRunToken = new WeakMap<Request, RunTokenDecision>()
237
245
  guard.assertCanServeHttp({ production: process.env.NODE_ENV === "production" })
238
246
  const apiBrowserPolicy = server.getApiBrowserPolicy()
239
247
 
@@ -261,7 +269,20 @@ export function createSixbApi(server: SixbServer) {
261
269
  maxAge: 600,
262
270
  })
263
271
  )
272
+ // A runner's session requests, before anything parses them: a runner token speaks only there.
273
+ const serveRunnerSession = agentRunSessionHandler(host)
274
+ app.onRequest(async ({ request }) => (await serveRunnerSession(request)) ?? undefined)
275
+ app.onRequest(async ({ request }) => {
276
+ // An Agent's commands, as their run: decided before Elysia parses the body, which the approval
277
+ // gate reads from a copy. No session, share or cookie speaks for such a request.
278
+ const runToken = requestRunToken(request)
279
+ if (runToken === undefined) return undefined
280
+ const decision = await resolveRunTokenRequest({ host, request, token: runToken })
281
+ preparedRunToken.set(request, decision)
282
+ return decision.kind === "deny" ? decision.response : undefined
283
+ })
264
284
  app.onRequest(async ({ request, set }) => {
285
+ if (preparedRunToken.has(request)) return undefined
265
286
  // Resolve Share intent before Elysia parses route inputs. Otherwise an unsupported route or an
266
287
  // invalid shared session could escape through a route-specific 4xx before this boundary ran.
267
288
  // CORS is registered first so allowed app origins can read these generic boundary responses.
@@ -286,6 +307,18 @@ export function createSixbApi(server: SixbServer) {
286
307
  // never choose between a principal SDK and the ambient runtime themselves.
287
308
  app
288
309
  .derive(async ({ request }) => {
310
+ const runToken = preparedRunToken.get(request)
311
+ preparedRunToken.delete(request)
312
+ if (runToken?.kind === "allow") {
313
+ const { runExecution, ...agentState } = runToken.state
314
+ return {
315
+ auth: { kind: "allow" as const, session: null },
316
+ sharedAccessCookies: null,
317
+ ...agentState,
318
+ sixb: bindAgentRunRequestExecution(host, { signal: request.signal, ...runExecution }),
319
+ }
320
+ }
321
+
289
322
  const shared =
290
323
  preparedSharedAccess.get(request) ?? (await sharedAccess.resolveRequest(request))
291
324
  preparedSharedAccess.delete(request)
@@ -315,17 +348,6 @@ export function createSixbApi(server: SixbServer) {
315
348
  }
316
349
  }
317
350
 
318
- const internalAuthState = consumeInternalRequestAuthState(request)
319
- if (internalAuthState) {
320
- const { runExecution, ...agentState } = internalAuthState
321
- return {
322
- auth: { kind: "allow" as const, session: null },
323
- sharedAccessCookies: null,
324
- ...agentState,
325
- sixb: bindAgentGatewayRequestExecution(host, { signal: request.signal, ...runExecution }),
326
- }
327
- }
328
-
329
351
  const auth = await guard.resolve(request)
330
352
  if (auth.kind === "deny" || !auth.session?.authenticated) {
331
353
  return {
@@ -1,4 +0,0 @@
1
- import type { SixbHostView } from "@sixb/core";
2
- import type { Elysia } from "elysia";
3
- export declare function registerAgentApiGatewayRoutes(app: Elysia, host: SixbHostView): void;
4
- //# sourceMappingURL=agent-api-gateway.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent-api-gateway.d.ts","sourceRoot":"","sources":["../../src/routes/agent-api-gateway.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAiB9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAkBpC,wBAAgB,6BAA6B,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,QAuB5E"}