@sixb/server 0.1.21 → 0.1.22

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 (165) hide show
  1. package/dist/artifacts/frame.d.ts +5 -0
  2. package/dist/artifacts/frame.d.ts.map +1 -1
  3. package/dist/auth/browser-origin.d.ts +5 -1
  4. package/dist/auth/browser-origin.d.ts.map +1 -1
  5. package/dist/auth/experience.d.ts +1 -0
  6. package/dist/auth/experience.d.ts.map +1 -1
  7. package/dist/auth/public-routes.d.ts.map +1 -1
  8. package/dist/auth/responses.d.ts +1 -1
  9. package/dist/auth/responses.d.ts.map +1 -1
  10. package/dist/auth/scope.d.ts +19 -3
  11. package/dist/auth/scope.d.ts.map +1 -1
  12. package/dist/index.js +10093 -7553
  13. package/dist/index.js.map +51 -39
  14. package/dist/models/display.d.ts +27 -0
  15. package/dist/models/display.d.ts.map +1 -1
  16. package/dist/openapi/components.d.ts +14 -0
  17. package/dist/openapi/components.d.ts.map +1 -0
  18. package/dist/openapi/tags.d.ts +14 -2
  19. package/dist/openapi/tags.d.ts.map +1 -1
  20. package/dist/registerRoutes.d.ts.map +1 -1
  21. package/dist/routes/actions.d.ts +5 -5
  22. package/dist/routes/agent-api-gateway.d.ts.map +1 -1
  23. package/dist/routes/agent-approval-gate.d.ts +27 -0
  24. package/dist/routes/agent-approval-gate.d.ts.map +1 -0
  25. package/dist/routes/agent-approvals.d.ts +599 -0
  26. package/dist/routes/agent-approvals.d.ts.map +1 -0
  27. package/dist/routes/agent-children.d.ts +318 -0
  28. package/dist/routes/agent-children.d.ts.map +1 -0
  29. package/dist/routes/agent-memory.d.ts +267 -0
  30. package/dist/routes/agent-memory.d.ts.map +1 -0
  31. package/dist/routes/agents.d.ts +999 -80
  32. package/dist/routes/agents.d.ts.map +1 -1
  33. package/dist/routes/ai-accounting.d.ts.map +1 -1
  34. package/dist/routes/artifact-frames.d.ts +3 -3
  35. package/dist/routes/artifact-frames.d.ts.map +1 -1
  36. package/dist/routes/artifacts.d.ts +790 -134
  37. package/dist/routes/artifacts.d.ts.map +1 -1
  38. package/dist/routes/auth.d.ts +116 -10
  39. package/dist/routes/auth.d.ts.map +1 -1
  40. package/dist/routes/connector-connection-runs.d.ts +50 -50
  41. package/dist/routes/connectors.d.ts +2 -2
  42. package/dist/routes/datasets.d.ts +20 -20
  43. package/dist/routes/events.d.ts +4 -4
  44. package/dist/routes/files.d.ts +14 -14
  45. package/dist/routes/files.d.ts.map +1 -1
  46. package/dist/routes/links.d.ts +2 -2
  47. package/dist/routes/logs.d.ts +5 -5
  48. package/dist/routes/model-calls.d.ts +155 -0
  49. package/dist/routes/model-calls.d.ts.map +1 -0
  50. package/dist/routes/model-generations.d.ts +400 -0
  51. package/dist/routes/model-generations.d.ts.map +1 -0
  52. package/dist/routes/models.d.ts +434 -1
  53. package/dist/routes/models.d.ts.map +1 -1
  54. package/dist/routes/objects.d.ts +71 -40
  55. package/dist/routes/objects.d.ts.map +1 -1
  56. package/dist/routes/observed-agent-threads.d.ts +682 -0
  57. package/dist/routes/observed-agent-threads.d.ts.map +1 -0
  58. package/dist/routes/ontology.d.ts +66 -62
  59. package/dist/routes/ontology.d.ts.map +1 -1
  60. package/dist/routes/pipelines.d.ts +24 -24
  61. package/dist/routes/projections.d.ts +55 -55
  62. package/dist/routes/rules.d.ts +2 -2
  63. package/dist/routes/share-grants.d.ts +9 -9
  64. package/dist/routes/syncs.d.ts +46 -46
  65. package/dist/routes/users.d.ts +117 -0
  66. package/dist/routes/users.d.ts.map +1 -0
  67. package/dist/routes/webhook-runs.d.ts +1 -1
  68. package/dist/routes/workflows.d.ts +118 -52
  69. package/dist/routes/workflows.d.ts.map +1 -1
  70. package/dist/routes/ws/agents.d.ts +7 -2
  71. package/dist/routes/ws/agents.d.ts.map +1 -1
  72. package/dist/routes/ws/events.d.ts +6 -6
  73. package/dist/routes/ws/logs.d.ts +14 -14
  74. package/dist/schemas/actions.d.ts +15 -15
  75. package/dist/schemas/activity.d.ts +48 -28
  76. package/dist/schemas/activity.d.ts.map +1 -1
  77. package/dist/schemas/agent-approvals.d.ts +1091 -0
  78. package/dist/schemas/agent-approvals.d.ts.map +1 -0
  79. package/dist/schemas/agent-memory.d.ts +250 -0
  80. package/dist/schemas/agent-memory.d.ts.map +1 -0
  81. package/dist/schemas/agents.d.ts +5442 -369
  82. package/dist/schemas/agents.d.ts.map +1 -1
  83. package/dist/schemas/ai-accounting.d.ts +1290 -411
  84. package/dist/schemas/ai-accounting.d.ts.map +1 -1
  85. package/dist/schemas/ai-limits.d.ts +10 -10
  86. package/dist/schemas/ai-usage.d.ts +12 -0
  87. package/dist/schemas/ai-usage.d.ts.map +1 -1
  88. package/dist/schemas/artifacts.d.ts +650 -98
  89. package/dist/schemas/artifacts.d.ts.map +1 -1
  90. package/dist/schemas/auth.d.ts +119 -46
  91. package/dist/schemas/auth.d.ts.map +1 -1
  92. package/dist/schemas/connectors.d.ts +22 -22
  93. package/dist/schemas/datasets.d.ts +98 -98
  94. package/dist/schemas/event-payloads.d.ts +6 -6
  95. package/dist/schemas/events.d.ts +26 -26
  96. package/dist/schemas/events.d.ts.map +1 -1
  97. package/dist/schemas/files.d.ts +24 -24
  98. package/dist/schemas/links.d.ts +2 -2
  99. package/dist/schemas/logs.d.ts +32 -32
  100. package/dist/schemas/models.d.ts +8889 -10
  101. package/dist/schemas/models.d.ts.map +1 -1
  102. package/dist/schemas/objects.d.ts +48 -12
  103. package/dist/schemas/objects.d.ts.map +1 -1
  104. package/dist/schemas/ontology.d.ts +127 -104
  105. package/dist/schemas/ontology.d.ts.map +1 -1
  106. package/dist/schemas/pipelines.d.ts +132 -132
  107. package/dist/schemas/projections.d.ts +314 -314
  108. package/dist/schemas/rules.d.ts +4 -4
  109. package/dist/schemas/share-grants.d.ts +30 -30
  110. package/dist/schemas/syncs.d.ts +49 -49
  111. package/dist/schemas/users.d.ts +72 -0
  112. package/dist/schemas/users.d.ts.map +1 -0
  113. package/dist/schemas/webhook-runs.d.ts +6 -6
  114. package/dist/schemas/workflows.d.ts +701 -186
  115. package/dist/schemas/workflows.d.ts.map +1 -1
  116. package/dist/server.d.ts +1 -0
  117. package/dist/server.d.ts.map +1 -1
  118. package/dist/utils/http.d.ts.map +1 -1
  119. package/package.json +7 -7
  120. package/src/artifacts/frame.ts +6 -1
  121. package/src/auth/browser-origin.ts +8 -3
  122. package/src/auth/experience.ts +1 -1
  123. package/src/auth/guard.ts +2 -2
  124. package/src/auth/public-routes.ts +6 -0
  125. package/src/auth/responses.ts +7 -6
  126. package/src/auth/scope.ts +32 -3
  127. package/src/models/display.ts +61 -16
  128. package/src/openapi/components.ts +54 -0
  129. package/src/openapi/tags.ts +12 -0
  130. package/src/registerRoutes.ts +14 -0
  131. package/src/routes/agent-api-gateway.ts +115 -91
  132. package/src/routes/agent-approval-gate.ts +213 -0
  133. package/src/routes/agent-approvals.ts +299 -0
  134. package/src/routes/agent-children.ts +209 -0
  135. package/src/routes/agent-memory.ts +210 -0
  136. package/src/routes/agents.ts +363 -142
  137. package/src/routes/ai-accounting.ts +4 -0
  138. package/src/routes/artifact-frames.ts +14 -8
  139. package/src/routes/artifacts.ts +297 -22
  140. package/src/routes/auth.ts +306 -13
  141. package/src/routes/files.ts +6 -7
  142. package/src/routes/model-calls.ts +120 -0
  143. package/src/routes/model-generations.ts +245 -0
  144. package/src/routes/models.ts +116 -9
  145. package/src/routes/objects.ts +55 -61
  146. package/src/routes/observed-agent-threads.ts +253 -0
  147. package/src/routes/ontology.ts +1 -0
  148. package/src/routes/users.ts +73 -0
  149. package/src/routes/workflows.ts +6 -9
  150. package/src/routes/ws/agents.ts +10 -5
  151. package/src/schemas/activity.ts +2 -0
  152. package/src/schemas/agent-approvals.ts +129 -0
  153. package/src/schemas/agent-memory.ts +96 -0
  154. package/src/schemas/agents.ts +239 -0
  155. package/src/schemas/ai-accounting.ts +40 -4
  156. package/src/schemas/ai-usage.ts +10 -0
  157. package/src/schemas/artifacts.ts +91 -3
  158. package/src/schemas/auth.ts +25 -0
  159. package/src/schemas/models.ts +197 -1
  160. package/src/schemas/objects.ts +181 -0
  161. package/src/schemas/ontology.ts +1 -0
  162. package/src/schemas/users.ts +24 -0
  163. package/src/schemas/workflows.ts +2 -0
  164. package/src/server.ts +9 -10
  165. package/src/utils/http.ts +2 -0
@@ -63,6 +63,10 @@ function serializeOverview(overview: AiAccountingOverview) {
63
63
  modelId: model.modelId,
64
64
  ...serializeAggregate(model),
65
65
  })),
66
+ kinds: overview.kinds.map((kind) => ({
67
+ ...(kind.modelKind === undefined ? {} : { modelKind: kind.modelKind }),
68
+ ...serializeAggregate(kind),
69
+ })),
66
70
  agents: overview.agents.map((agent) => ({
67
71
  kind: agent.kind,
68
72
  ...(agent.kind === "workflowAgent"
@@ -4,6 +4,8 @@ import {
4
4
  ARTIFACT_FRAME_ROUTE_PREFIX,
5
5
  FRAME_ASSETS,
6
6
  FRAME_REFERENCE_PREFIX,
7
+ frameEntries,
8
+ frameLayout,
7
9
  injectFrameAssets,
8
10
  resolveArtifactFrame,
9
11
  rewriteFrameReferences,
@@ -20,9 +22,9 @@ interface FrameContext {
20
22
  }
21
23
 
22
24
  /**
23
- * Serves a deck's files to its sandboxed frame, under the token a frame link carries: the token
24
- * is the credential, so the route is public. The entry gets the kit and the runtime, and the kit
25
- * and runtime are served beside the files. Hidden from OpenAPI: clients receive frame links, they
25
+ * Serves a version's files to its sandboxed frame, under the token a frame link carries: the token
26
+ * is the credential, so the route is public. Each entry gets its layout's kit and the runtime,
27
+ * which are served beside the files. Hidden from OpenAPI: clients receive frame links, they
26
28
  * never build them.
27
29
  */
28
30
  export function registerArtifactFrameRoutes(
@@ -59,12 +61,12 @@ async function frameResponse(
59
61
  }
60
62
 
61
63
  // A frame link opens only in a frame. Opened as a page on the API's origin, its sandbox would
62
- // still let it show dialogs and open windows that escape the sandbox, under the API's address.
64
+ // still let it show dialogs under the API's address, with no app policy to hold where it goes.
63
65
  if (request.headers.get("sec-fetch-dest") === "document") return notFound()
64
66
 
65
67
  const storage = host.storage.artifacts
66
68
  if (!storage) return notFound()
67
- // An unknown or expired token, a deleted version, and one that is no deck all answer one 404.
69
+ // An unknown or expired token, a deleted version, and a kind with no frame all answer one 404.
68
70
  const frame = await resolveArtifactFrame({
69
71
  projectId: host.id,
70
72
  storage,
@@ -82,7 +84,7 @@ async function frameResponse(
82
84
  }
83
85
  let lent = false
84
86
  if (path?.startsWith(FRAME_REFERENCE_PREFIX)) {
85
- // A file another artifact lends the deck: only one its frame was issued with, at that version.
87
+ // A file another artifact lends this one: only one its frame was issued with, at that version.
86
88
  const match = /^([^/@]+)@(\d+)\/(.+)$/.exec(path.slice(FRAME_REFERENCE_PREFIX.length))
87
89
  const target = frame.targets.find(
88
90
  (candidate) =>
@@ -105,14 +107,18 @@ async function frameResponse(
105
107
  const file = version.files.find((candidate) => candidate.path === path)
106
108
  if (!file) return notFound()
107
109
 
108
- if (!lent && file.path === version.entry) {
110
+ const layout = frameLayout(version.outline.kind)
111
+ if (!lent && layout && frameEntries(version).includes(file.path)) {
109
112
  const opened = await openFileRef(host.blobStorage, file.file)
110
113
  if (!opened) return notFound()
111
114
  headers.set("content-type", "text/html; charset=utf-8")
112
115
  headers.set("cache-control", "private, no-cache")
113
116
  if (options.head) return new Response(null, { headers })
114
117
  const text = await new Response(opened.body).text()
115
- return new Response(injectFrameAssets(rewriteFrameReferences(text, frame.targets)), { headers })
118
+ return new Response(
119
+ injectFrameAssets(rewriteFrameReferences(text, frame.targets, file.path), layout, file.path),
120
+ { headers }
121
+ )
116
122
  }
117
123
 
118
124
  const response = await createFileContentResponse({
@@ -1,4 +1,5 @@
1
1
  import {
2
+ type ArtifactAccess,
2
3
  type ArtifactContentInput,
3
4
  type ArtifactRecord,
4
5
  ArtifactRequestError,
@@ -7,7 +8,10 @@ import {
7
8
  type PublishedArtifact,
8
9
  type SixbHostView,
9
10
  } from "@sixb/core"
10
- import { createArtifactFrame } from "@sixb/core/internal/artifacts/frames"
11
+ import {
12
+ createArtifactFrame,
13
+ serializeArtifactQueryResult,
14
+ } from "@sixb/core/internal/artifacts/frames"
11
15
  import type { Elysia } from "elysia"
12
16
  import { ZodError } from "zod"
13
17
  import { accessTokenSecurityRequirement } from "../auth/access-token-boundary"
@@ -24,15 +28,24 @@ import {
24
28
  ArtifactListQuerySchema,
25
29
  ArtifactListResponseSchema,
26
30
  ArtifactParamsSchema,
31
+ ArtifactQueryParamsSchema,
27
32
  ArtifactResponseSchema,
33
+ ArtifactStateParamsSchema,
34
+ ArtifactStateResponseSchema,
28
35
  ArtifactVersionParamsSchema,
29
36
  ArtifactVersionSchema,
37
+ ClearArtifactStateResponseSchema,
30
38
  DeleteArtifactResponseSchema,
39
+ DeleteArtifactStateResponseSchema,
31
40
  PublishArtifactBodySchema,
41
+ PublishArtifactVersionBodySchema,
32
42
  PublishedArtifactResponseSchema,
43
+ SetArtifactStateBodySchema,
44
+ SetArtifactStateResponseSchema,
33
45
  } from "../schemas/artifacts"
34
46
  import { FileContentQuerySchema } from "../schemas/files"
35
47
  import { handleRouteError, parseOptionalInt, toIsoString } from "../utils/http"
48
+ import { handleObjectQueryError } from "./objects"
36
49
 
37
50
  type RouteSet = { status?: number | string }
38
51
 
@@ -103,26 +116,58 @@ function notFound(set: RouteSet) {
103
116
  return { error: "Artifact not found", code: "artifact_not_found" as const }
104
117
  }
105
118
 
119
+ /**
120
+ * Why a read found nothing: 404 when there is no such artifact, 403 `not_shared` when there is one
121
+ * the caller cannot read, so a page can say it is not shared in this conversation.
122
+ */
123
+ async function refusal(context: unknown, artifactId: string, set: RouteSet) {
124
+ return refusalFor(await requireRequestSixb(context).artifacts.access(artifactId), set)
125
+ }
126
+
127
+ /** The refusal for what the caller may do with an artifact, once that is known. */
128
+ function refusalFor(access: ArtifactAccess | null, set: RouteSet) {
129
+ if (access !== "none") return notFound(set)
130
+
131
+ set.status = 403
132
+ return {
133
+ error: "Artifact not shared in a conversation you read",
134
+ code: "not_shared" as const,
135
+ }
136
+ }
137
+
106
138
  function handleArtifactRouteError(error: unknown, set: RouteSet) {
107
139
  if (error instanceof ArtifactRequestError) {
108
140
  switch (error.code) {
109
141
  case "artifact_not_found":
142
+ case "query_not_found":
110
143
  set.status = 404
111
144
  break
112
145
  case "artifact_kind_mismatch":
146
+ case "artifact_moved":
147
+ case "query_invalid":
113
148
  set.status = 409
114
149
  break
115
150
  case "invalid_artifact":
151
+ case "invalid_state":
116
152
  set.status = 400
117
153
  break
154
+ case "state_full":
155
+ set.status = 413
156
+ break
118
157
  case "not_allowed":
158
+ case "not_shared":
159
+ case "read_only":
119
160
  set.status = 403
120
161
  break
121
162
  case "storage_unavailable":
122
163
  set.status = 501
123
164
  break
124
165
  }
125
- return { error: error.message, code: error.code }
166
+ return {
167
+ error: error.message,
168
+ code: error.code,
169
+ ...(error.latest ? { latest: error.latest } : {}),
170
+ }
126
171
  }
127
172
  if (error instanceof ZodError) {
128
173
  set.status = 400
@@ -131,6 +176,16 @@ function handleArtifactRouteError(error: unknown, set: RouteSet) {
131
176
  return handleRouteError(error, set)
132
177
  }
133
178
 
179
+ /** The artifact error body, for a route that declares its responses in OpenAPI. */
180
+ function artifactErrorResponse(status: number) {
181
+ return {
182
+ description: `Response for status ${status}`,
183
+ content: {
184
+ "application/json": { schema: { $ref: "#/components/schemas/ArtifactErrorResponse" } },
185
+ },
186
+ }
187
+ }
188
+
134
189
  const publishResponses = {
135
190
  201: PublishedArtifactResponseSchema,
136
191
  400: ArtifactErrorResponseSchema,
@@ -156,7 +211,9 @@ async function artifactFileContentResponse(
156
211
  context.params.artifactId,
157
212
  versionParam(context.params.version)
158
213
  )
159
- const file = version?.files.find((candidate) => candidate.path === query.path)
214
+ if (!version) return await refusal(context, context.params.artifactId, context.set)
215
+
216
+ const file = version.files.find((candidate) => candidate.path === query.path)
160
217
  const response =
161
218
  file &&
162
219
  (await createFileContentResponse({
@@ -213,7 +270,8 @@ export function registerArtifactRoutes(app: Elysia, host: SixbHostView) {
213
270
  },
214
271
  detail: {
215
272
  summary: "List artifacts",
216
- description: "The caller's artifacts, most recently updated first.",
273
+ description:
274
+ "The caller's artifacts, most recently updated first. With thread, every artifact the conversation shares, for whoever reads it.",
217
275
  tags: [OPENAPI_TAGS.artifacts.name],
218
276
  operationId: "listArtifacts",
219
277
  security: accessTokenSecurityRequirement("listArtifacts"),
@@ -249,13 +307,26 @@ export function registerArtifactRoutes(app: Elysia, host: SixbHostView) {
249
307
  "/api/artifacts/:artifactId",
250
308
  async (context) => {
251
309
  try {
252
- const sixb = requireRequestSixb(context)
253
- const artifact = await sixb.artifacts.get(context.params.artifactId)
254
- const versions = artifact && (await sixb.artifacts.listVersions(artifact.id))
255
- if (!artifact || !versions) return notFound(context.set)
310
+ const { artifactId } = context.params
311
+ // What the caller may do is decided once; the reads after it need no second decision.
312
+ const access = await requireRequestSixb(context).artifacts.access(artifactId)
313
+ const storage = host.storage.artifacts
314
+ if (!storage || access === null || access === "none") {
315
+ return refusalFor(access, context.set)
316
+ }
317
+
318
+ const at = { projectId: host.id, id: artifactId }
319
+ const [artifact, versions] = await Promise.all([
320
+ storage.get(at),
321
+ storage.listVersions({ projectId: host.id, artifactId }),
322
+ ])
323
+ // Deleted since the decision.
324
+ if (!artifact) return notFound(context.set)
325
+
256
326
  return ArtifactResponseSchema.parse({
257
327
  artifact: artifactBody(artifact),
258
328
  versions: versions.versions.map(versionBody),
329
+ access,
259
330
  })
260
331
  } catch (error) {
261
332
  return handleArtifactRouteError(error, context.set)
@@ -265,6 +336,7 @@ export function registerArtifactRoutes(app: Elysia, host: SixbHostView) {
265
336
  params: ArtifactParamsSchema,
266
337
  response: {
267
338
  200: ArtifactResponseSchema,
339
+ 403: ArtifactErrorResponseSchema,
268
340
  404: ArtifactErrorResponseSchema,
269
341
  501: ArtifactErrorResponseSchema,
270
342
  },
@@ -280,11 +352,22 @@ export function registerArtifactRoutes(app: Elysia, host: SixbHostView) {
280
352
  "/api/artifacts/:artifactId",
281
353
  async (context) => {
282
354
  try {
283
- const deleted = await requireRequestSixb(context).artifacts.delete(
284
- context.params.artifactId
285
- )
286
- if (!deleted) return notFound(context.set)
287
- return DeleteArtifactResponseSchema.parse({ deleted: true })
355
+ const artifacts = requireRequestSixb(context).artifacts
356
+ const { artifactId } = context.params
357
+ if (await artifacts.delete(artifactId)) {
358
+ return DeleteArtifactResponseSchema.parse({ deleted: true })
359
+ }
360
+
361
+ // Only its owner deletes it, from every conversation that shares it.
362
+ const access = await artifacts.access(artifactId)
363
+ if (access === "update" || access === "read") {
364
+ context.set.status = 403
365
+ return {
366
+ error: "Only the artifact's owner can delete it",
367
+ code: "not_allowed" as const,
368
+ }
369
+ }
370
+ return await refusal(context, artifactId, context.set)
288
371
  } catch (error) {
289
372
  return handleArtifactRouteError(error, context.set)
290
373
  }
@@ -293,26 +376,161 @@ export function registerArtifactRoutes(app: Elysia, host: SixbHostView) {
293
376
  params: ArtifactParamsSchema,
294
377
  response: {
295
378
  200: DeleteArtifactResponseSchema,
379
+ 403: ArtifactErrorResponseSchema,
296
380
  404: ArtifactErrorResponseSchema,
297
381
  501: ArtifactErrorResponseSchema,
298
382
  },
299
383
  detail: {
300
384
  summary: "Delete an artifact",
301
- description: "Deletes the artifact with every version.",
385
+ description:
386
+ "Deletes the artifact with every version, from every conversation that shares it. Only its owner can.",
302
387
  tags: [OPENAPI_TAGS.artifacts.name],
303
388
  operationId: "deleteArtifact",
304
389
  security: accessTokenSecurityRequirement("deleteArtifact"),
305
390
  },
306
391
  }
307
392
  )
393
+ .get(
394
+ "/api/artifacts/:artifactId/state",
395
+ async (context) => {
396
+ try {
397
+ const entries = await requireRequestSixb(context)
398
+ .artifacts.state(context.params.artifactId)
399
+ .entries()
400
+ return ArtifactStateResponseSchema.parse({
401
+ entries: entries.map((entry) => ({
402
+ ...entry,
403
+ updatedAt: toIsoString(entry.updatedAt),
404
+ })),
405
+ })
406
+ } catch (error) {
407
+ return handleArtifactRouteError(error, context.set)
408
+ }
409
+ },
410
+ {
411
+ params: ArtifactParamsSchema,
412
+ response: {
413
+ 200: ArtifactStateResponseSchema,
414
+ 403: ArtifactErrorResponseSchema,
415
+ 404: ArtifactErrorResponseSchema,
416
+ 501: ArtifactErrorResponseSchema,
417
+ },
418
+ detail: {
419
+ summary: "Read what a page keeps",
420
+ description:
421
+ "Every value the artifact keeps for the caller as its reader, as a page keeps it with sixb.state, across its versions.",
422
+ tags: [OPENAPI_TAGS.artifacts.name],
423
+ operationId: "getArtifactState",
424
+ security: accessTokenSecurityRequirement("getArtifactState"),
425
+ },
426
+ }
427
+ )
428
+ .put(
429
+ "/api/artifacts/:artifactId/state/:key",
430
+ async (context) => {
431
+ try {
432
+ const body = SetArtifactStateBodySchema.parse(context.body)
433
+ const entry = await requireRequestSixb(context)
434
+ .artifacts.state(context.params.artifactId)
435
+ .set(context.params.key, body.value)
436
+ return SetArtifactStateResponseSchema.parse({
437
+ ...entry,
438
+ updatedAt: toIsoString(entry.updatedAt),
439
+ })
440
+ } catch (error) {
441
+ return handleArtifactRouteError(error, context.set)
442
+ }
443
+ },
444
+ {
445
+ params: ArtifactStateParamsSchema,
446
+ body: SetArtifactStateBodySchema,
447
+ response: {
448
+ 200: SetArtifactStateResponseSchema,
449
+ 400: ArtifactErrorResponseSchema,
450
+ 403: ArtifactErrorResponseSchema,
451
+ 404: ArtifactErrorResponseSchema,
452
+ 413: ArtifactErrorResponseSchema,
453
+ 501: ArtifactErrorResponseSchema,
454
+ },
455
+ detail: {
456
+ summary: "Keep a value for a page",
457
+ description:
458
+ "Keeps a JSON value under the key for the caller, replacing one there. Refused with 413 state_full past the limits.",
459
+ tags: [OPENAPI_TAGS.artifacts.name],
460
+ operationId: "setArtifactState",
461
+ security: accessTokenSecurityRequirement("setArtifactState"),
462
+ },
463
+ }
464
+ )
465
+ .delete(
466
+ "/api/artifacts/:artifactId/state/:key",
467
+ async (context) => {
468
+ try {
469
+ const deleted = await requireRequestSixb(context)
470
+ .artifacts.state(context.params.artifactId)
471
+ .delete(context.params.key)
472
+ return DeleteArtifactStateResponseSchema.parse({ deleted })
473
+ } catch (error) {
474
+ return handleArtifactRouteError(error, context.set)
475
+ }
476
+ },
477
+ {
478
+ params: ArtifactStateParamsSchema,
479
+ response: {
480
+ 200: DeleteArtifactStateResponseSchema,
481
+ 400: ArtifactErrorResponseSchema,
482
+ 403: ArtifactErrorResponseSchema,
483
+ 404: ArtifactErrorResponseSchema,
484
+ 501: ArtifactErrorResponseSchema,
485
+ },
486
+ detail: {
487
+ summary: "Delete a value a page keeps",
488
+ tags: [OPENAPI_TAGS.artifacts.name],
489
+ operationId: "deleteArtifactStateValue",
490
+ security: accessTokenSecurityRequirement("deleteArtifactStateValue"),
491
+ },
492
+ }
493
+ )
494
+ .delete(
495
+ "/api/artifacts/:artifactId/state",
496
+ async (context) => {
497
+ try {
498
+ const cleared = await requireRequestSixb(context)
499
+ .artifacts.state(context.params.artifactId)
500
+ .clear()
501
+ return ClearArtifactStateResponseSchema.parse({ cleared })
502
+ } catch (error) {
503
+ return handleArtifactRouteError(error, context.set)
504
+ }
505
+ },
506
+ {
507
+ params: ArtifactParamsSchema,
508
+ response: {
509
+ 200: ClearArtifactStateResponseSchema,
510
+ 403: ArtifactErrorResponseSchema,
511
+ 404: ArtifactErrorResponseSchema,
512
+ 501: ArtifactErrorResponseSchema,
513
+ },
514
+ detail: {
515
+ summary: "Reset what a page keeps",
516
+ description: "Deletes every value the artifact keeps for the caller.",
517
+ tags: [OPENAPI_TAGS.artifacts.name],
518
+ operationId: "clearArtifactState",
519
+ security: accessTokenSecurityRequirement("clearArtifactState"),
520
+ },
521
+ }
522
+ )
308
523
  .post(
309
524
  "/api/artifacts/:artifactId/versions",
310
525
  async (context) => {
311
526
  try {
312
- const body = PublishArtifactBodySchema.parse(context.body)
527
+ const body = PublishArtifactVersionBodySchema.parse(context.body)
313
528
  const published = await requireRequestSixb(context).artifacts.publish(
314
529
  context.params.artifactId,
315
- contentInput(body)
530
+ {
531
+ ...contentInput(body),
532
+ ...(body.baseVersion === undefined ? {} : { baseVersion: body.baseVersion }),
533
+ }
316
534
  )
317
535
  context.set.status = 201
318
536
  return serializePublished(published)
@@ -322,11 +540,12 @@ export function registerArtifactRoutes(app: Elysia, host: SixbHostView) {
322
540
  },
323
541
  {
324
542
  params: ArtifactParamsSchema,
325
- body: PublishArtifactBodySchema,
543
+ body: PublishArtifactVersionBodySchema,
326
544
  response: publishResponses,
327
545
  detail: {
328
546
  summary: "Publish an artifact's next version",
329
- description: "The kind must be the artifact's. The new version becomes the latest.",
547
+ description:
548
+ "The kind must be the artifact's. The new version becomes the latest. With baseVersion, it is refused with 409 artifact_moved when another version was published since.",
330
549
  tags: [OPENAPI_TAGS.artifacts.name],
331
550
  operationId: "publishArtifactVersion",
332
551
  security: accessTokenSecurityRequirement("publishArtifactVersion"),
@@ -345,7 +564,8 @@ export function registerArtifactRoutes(app: Elysia, host: SixbHostView) {
345
564
  context.params.artifactId,
346
565
  versionParam(context.params.version)
347
566
  )
348
- if (!version || !storage) return notFound(context.set)
567
+ if (!storage) return notFound(context.set)
568
+ if (!version) return await refusal(context, context.params.artifactId, context.set)
349
569
  // Any kind but a deck is refused as `artifact_kind_mismatch`.
350
570
  const frame = await createArtifactFrame({
351
571
  projectId: host.id,
@@ -365,14 +585,15 @@ export function registerArtifactRoutes(app: Elysia, host: SixbHostView) {
365
585
  params: ArtifactVersionParamsSchema,
366
586
  response: {
367
587
  200: ArtifactFrameResponseSchema,
588
+ 403: ArtifactErrorResponseSchema,
368
589
  404: ArtifactErrorResponseSchema,
369
590
  409: ArtifactErrorResponseSchema,
370
591
  501: ArtifactErrorResponseSchema,
371
592
  },
372
593
  detail: {
373
- summary: "Open a deck's version in a frame",
594
+ summary: "Open a version in a frame",
374
595
  description:
375
- "A short-lived path that serves a slides version's files to a sandboxed frame. It expires within an hour. Any other kind is refused with 409 artifact_kind_mismatch.",
596
+ "A short-lived path that serves the files of a version that opens in a sandboxed frame, as slides do. It expires within an hour. A kind that does not open in a frame is refused with 409 artifact_kind_mismatch.",
376
597
  tags: [OPENAPI_TAGS.artifacts.name],
377
598
  operationId: "createArtifactFrame",
378
599
  security: accessTokenSecurityRequirement("createArtifactFrame"),
@@ -387,7 +608,7 @@ export function registerArtifactRoutes(app: Elysia, host: SixbHostView) {
387
608
  context.params.artifactId,
388
609
  versionParam(context.params.version)
389
610
  )
390
- if (!version) return notFound(context.set)
611
+ if (!version) return await refusal(context, context.params.artifactId, context.set)
391
612
  return ArtifactVersionSchema.parse(versionBody(version))
392
613
  } catch (error) {
393
614
  return handleArtifactRouteError(error, context.set)
@@ -397,6 +618,7 @@ export function registerArtifactRoutes(app: Elysia, host: SixbHostView) {
397
618
  params: ArtifactVersionParamsSchema,
398
619
  response: {
399
620
  200: ArtifactVersionSchema,
621
+ 403: ArtifactErrorResponseSchema,
400
622
  404: ArtifactErrorResponseSchema,
401
623
  501: ArtifactErrorResponseSchema,
402
624
  },
@@ -409,6 +631,59 @@ export function registerArtifactRoutes(app: Elysia, host: SixbHostView) {
409
631
  },
410
632
  }
411
633
  )
634
+ .get(
635
+ "/api/artifacts/:artifactId/versions/:version/queries/:name",
636
+ async (context) => {
637
+ try {
638
+ const { artifactId, version, name } = context.params
639
+ const result = await requireRequestSixb(context).artifacts.query(artifactId, name, {
640
+ version: versionParam(version),
641
+ })
642
+ if (!result) return await refusal(context, artifactId, context.set)
643
+
644
+ // Typed by the ArtifactQueryResponse component, as the query route types its rows.
645
+ return serializeArtifactQueryResult(result)
646
+ } catch (error) {
647
+ // What the query itself runs into answers as the objects API answers it.
648
+ return error instanceof ArtifactRequestError || error instanceof ZodError
649
+ ? handleArtifactRouteError(error, context.set)
650
+ : handleObjectQueryError(error, context.set)
651
+ }
652
+ },
653
+ {
654
+ params: ArtifactQueryParamsSchema,
655
+ detail: {
656
+ summary: "Run an artifact's query",
657
+ description:
658
+ 'Runs the version\'s queries/<name>.json as the caller, with their rights: a type they cannot view is refused with 403, and a marked property they are not cleared for is left out of each row. Rows are serialized as POST /api/objects/query returns them, beside the schema of what they hold as the caller may view it. Use "latest" for the newest version. A query the ontology no longer admits is refused with 409 query_invalid.',
659
+ tags: [OPENAPI_TAGS.artifacts.name],
660
+ operationId: "getArtifactQuery",
661
+ security: accessTokenSecurityRequirement("getArtifactQuery"),
662
+ // Declared in OpenAPI, not zod, as the query route declares its own: the rows take the
663
+ // ObjectQueryObject component, so they are typed as that route's rows.
664
+ responses: {
665
+ 200: {
666
+ description: "Response for status 200",
667
+ content: {
668
+ "application/json": {
669
+ schema: { $ref: "#/components/schemas/ArtifactQueryResponse" },
670
+ },
671
+ },
672
+ },
673
+ 400: {
674
+ description: "Response for status 400",
675
+ content: {
676
+ "application/json": { schema: { $ref: "#/components/schemas/ErrorResponse" } },
677
+ },
678
+ },
679
+ 403: artifactErrorResponse(403),
680
+ 404: artifactErrorResponse(404),
681
+ 409: artifactErrorResponse(409),
682
+ 501: artifactErrorResponse(501),
683
+ },
684
+ },
685
+ }
686
+ )
412
687
  .get(
413
688
  "/api/artifacts/:artifactId/versions/:version/content",
414
689
  async (context) => artifactFileContentResponse(host, context),