@sixb/server 0.2.1 → 0.2.3

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 (153) hide show
  1. package/README.md +3 -3
  2. package/dist/artifacts/frame.d.ts.map +1 -1
  3. package/dist/auth/scope.d.ts +3 -0
  4. package/dist/auth/scope.d.ts.map +1 -1
  5. package/dist/auth/shared-access.d.ts +23 -0
  6. package/dist/auth/shared-access.d.ts.map +1 -1
  7. package/dist/connectors/http.d.ts +6 -1
  8. package/dist/connectors/http.d.ts.map +1 -1
  9. package/dist/index.js +2876 -667
  10. package/dist/index.js.map +43 -36
  11. package/dist/live/awareness.d.ts +48 -0
  12. package/dist/live/awareness.d.ts.map +1 -0
  13. package/dist/live/room.d.ts +198 -0
  14. package/dist/live/room.d.ts.map +1 -0
  15. package/dist/live/rooms.d.ts +67 -0
  16. package/dist/live/rooms.d.ts.map +1 -0
  17. package/dist/registerRoutes.d.ts.map +1 -1
  18. package/dist/routes/actions.d.ts +3 -3
  19. package/dist/routes/agent-approvals.d.ts +21 -11
  20. package/dist/routes/agent-approvals.d.ts.map +1 -1
  21. package/dist/routes/agent-children.d.ts +4 -4
  22. package/dist/routes/agent-computers.d.ts +146 -1
  23. package/dist/routes/agent-computers.d.ts.map +1 -1
  24. package/dist/routes/agent-runners.d.ts.map +1 -1
  25. package/dist/routes/agents.d.ts +152 -60
  26. package/dist/routes/agents.d.ts.map +1 -1
  27. package/dist/routes/artifact-frames.d.ts +2 -1
  28. package/dist/routes/artifact-frames.d.ts.map +1 -1
  29. package/dist/routes/artifacts.d.ts +1713 -178
  30. package/dist/routes/artifacts.d.ts.map +1 -1
  31. package/dist/routes/auth.d.ts +21 -21
  32. package/dist/routes/connector-connection-runs.d.ts +124 -5
  33. package/dist/routes/connector-connection-runs.d.ts.map +1 -1
  34. package/dist/routes/connector-connections.d.ts +9 -1
  35. package/dist/routes/connector-connections.d.ts.map +1 -1
  36. package/dist/routes/datasets.d.ts +5 -5
  37. package/dist/routes/events.d.ts +4 -4
  38. package/dist/routes/lake.d.ts +91 -0
  39. package/dist/routes/lake.d.ts.map +1 -0
  40. package/dist/routes/links.d.ts +6 -6
  41. package/dist/routes/logs.d.ts +2 -2
  42. package/dist/routes/model-generations.d.ts +2 -2
  43. package/dist/routes/objects.d.ts +6 -6
  44. package/dist/routes/objects.d.ts.map +1 -1
  45. package/dist/routes/observed-agent-threads.d.ts +21 -11
  46. package/dist/routes/observed-agent-threads.d.ts.map +1 -1
  47. package/dist/routes/ontology.d.ts +6 -6
  48. package/dist/routes/pipelines.d.ts +13 -9
  49. package/dist/routes/pipelines.d.ts.map +1 -1
  50. package/dist/routes/projections.d.ts +27 -27
  51. package/dist/routes/share-grants.d.ts +9 -9
  52. package/dist/routes/shared-access.d.ts +57 -2
  53. package/dist/routes/shared-access.d.ts.map +1 -1
  54. package/dist/routes/status.d.ts +11 -15
  55. package/dist/routes/status.d.ts.map +1 -1
  56. package/dist/routes/syncs.d.ts +9 -6
  57. package/dist/routes/syncs.d.ts.map +1 -1
  58. package/dist/routes/telemetry.d.ts +7 -7
  59. package/dist/routes/webhooks.d.ts.map +1 -1
  60. package/dist/routes/workflows.d.ts +14 -14
  61. package/dist/routes/ws/artifacts.d.ts +57 -0
  62. package/dist/routes/ws/artifacts.d.ts.map +1 -0
  63. package/dist/routes/ws/events.d.ts +8 -7
  64. package/dist/routes/ws/events.d.ts.map +1 -1
  65. package/dist/routes/ws/index.d.ts +2 -1
  66. package/dist/routes/ws/index.d.ts.map +1 -1
  67. package/dist/routes/ws/logs.d.ts +10 -10
  68. package/dist/routes/ws/shared-sockets.d.ts +52 -0
  69. package/dist/routes/ws/shared-sockets.d.ts.map +1 -0
  70. package/dist/schemas/actions.d.ts +7 -7
  71. package/dist/schemas/activity.d.ts +16 -16
  72. package/dist/schemas/agent-approvals.d.ts +27 -27
  73. package/dist/schemas/agents.d.ts +642 -196
  74. package/dist/schemas/agents.d.ts.map +1 -1
  75. package/dist/schemas/ai-accounting.d.ts +41 -41
  76. package/dist/schemas/ai-accounting.d.ts.map +1 -1
  77. package/dist/schemas/artifacts.d.ts +2106 -127
  78. package/dist/schemas/artifacts.d.ts.map +1 -1
  79. package/dist/schemas/auth.d.ts +63 -63
  80. package/dist/schemas/connectors.d.ts +180 -20
  81. package/dist/schemas/connectors.d.ts.map +1 -1
  82. package/dist/schemas/datasets.d.ts +44 -44
  83. package/dist/schemas/event-payloads.d.ts +2 -2
  84. package/dist/schemas/events.d.ts +26 -26
  85. package/dist/schemas/events.d.ts.map +1 -1
  86. package/dist/schemas/files.d.ts +12 -0
  87. package/dist/schemas/files.d.ts.map +1 -1
  88. package/dist/schemas/lake.d.ts +251 -0
  89. package/dist/schemas/lake.d.ts.map +1 -0
  90. package/dist/schemas/lineage.d.ts +56 -56
  91. package/dist/schemas/logs.d.ts +18 -18
  92. package/dist/schemas/models.d.ts +4 -4
  93. package/dist/schemas/objects.d.ts.map +1 -1
  94. package/dist/schemas/ontology.d.ts +14 -14
  95. package/dist/schemas/pipelines.d.ts +86 -64
  96. package/dist/schemas/pipelines.d.ts.map +1 -1
  97. package/dist/schemas/projections.d.ts +160 -160
  98. package/dist/schemas/projections.d.ts.map +1 -1
  99. package/dist/schemas/share-grants.d.ts +30 -30
  100. package/dist/schemas/shared-access.d.ts +17 -4
  101. package/dist/schemas/shared-access.d.ts.map +1 -1
  102. package/dist/schemas/status.d.ts +59 -79
  103. package/dist/schemas/status.d.ts.map +1 -1
  104. package/dist/schemas/syncs.d.ts +38 -22
  105. package/dist/schemas/syncs.d.ts.map +1 -1
  106. package/dist/schemas/telemetry.d.ts +26 -26
  107. package/dist/schemas/workflows.d.ts +71 -71
  108. package/dist/server.d.ts +13 -0
  109. package/dist/server.d.ts.map +1 -1
  110. package/dist/utils/ws.d.ts +3 -0
  111. package/dist/utils/ws.d.ts.map +1 -1
  112. package/package.json +11 -7
  113. package/src/artifacts/frame.ts +4 -13
  114. package/src/auth/scope.ts +10 -1
  115. package/src/auth/shared-access.ts +108 -12
  116. package/src/connectors/http.ts +35 -1
  117. package/src/live/README.md +136 -0
  118. package/src/live/awareness.ts +141 -0
  119. package/src/live/room.ts +933 -0
  120. package/src/live/rooms.ts +288 -0
  121. package/src/registerRoutes.ts +2 -0
  122. package/src/routes/agent-computers.ts +208 -14
  123. package/src/routes/agent-runners.ts +1 -0
  124. package/src/routes/agents.ts +52 -7
  125. package/src/routes/artifact-frames.ts +40 -12
  126. package/src/routes/artifacts.ts +713 -28
  127. package/src/routes/connector-connection-runs.ts +7 -12
  128. package/src/routes/connector-connections.ts +10 -7
  129. package/src/routes/lake.ts +73 -0
  130. package/src/routes/objects.ts +3 -9
  131. package/src/routes/pipelines.ts +1 -0
  132. package/src/routes/shared-access.ts +53 -1
  133. package/src/routes/status.ts +9 -4
  134. package/src/routes/syncs.ts +1 -0
  135. package/src/routes/webhooks.ts +44 -3
  136. package/src/routes/ws/artifacts.ts +138 -0
  137. package/src/routes/ws/events.ts +7 -2
  138. package/src/routes/ws/index.ts +13 -2
  139. package/src/routes/ws/shared-sockets.ts +152 -0
  140. package/src/schemas/agents.ts +71 -1
  141. package/src/schemas/ai-accounting.ts +1 -0
  142. package/src/schemas/artifacts.ts +255 -18
  143. package/src/schemas/connectors.ts +17 -2
  144. package/src/schemas/files.ts +12 -0
  145. package/src/schemas/lake.ts +53 -0
  146. package/src/schemas/objects.ts +1 -0
  147. package/src/schemas/pipelines.ts +2 -0
  148. package/src/schemas/projections.ts +2 -2
  149. package/src/schemas/shared-access.ts +16 -0
  150. package/src/schemas/status.ts +16 -22
  151. package/src/schemas/syncs.ts +2 -0
  152. package/src/server.ts +35 -4
  153. package/src/utils/ws.ts +7 -0
@@ -17,6 +17,8 @@ import {
17
17
  import { agentRunStreamId } from "@sixb/core/internal/agents/streams"
18
18
  import { resolveFileRefAtPath } from "@sixb/core/internal/blob-storage"
19
19
  import {
20
+ type AgentBackgroundCommandRef,
21
+ type AgentComputerBackgroundCommand,
20
22
  type AgentContextCheckpointRecord,
21
23
  type AgentMessageRecord,
22
24
  type AgentRunDiagnostic,
@@ -126,7 +128,7 @@ export async function serializeThreads(
126
128
  title: thread.title,
127
129
  sandboxParams: thread.sandboxParams,
128
130
  runsOn: thread.runsOn,
129
- computer: placeOf(thread),
131
+ ...placeOf(thread),
130
132
  movedAt: thread.movedAt ? toIsoString(thread.movedAt) : undefined,
131
133
  sandboxState: thread.sandboxState && {
132
134
  name: thread.sandboxState.name,
@@ -153,14 +155,19 @@ export async function serializeThread(
153
155
  return serialized
154
156
  }
155
157
 
156
- /** Where each of the viewer's own computer threads runs, and whether its folder is open now. */
158
+ /**
159
+ * Where each of the viewer's own computer threads runs, whether its folder is open now, and the
160
+ * background commands their `sixb` runs for it.
161
+ */
157
162
  async function computerPlaces(
158
163
  host: SixbHostView,
159
164
  threads: readonly AgentThreadView[],
160
165
  viewer: Principal
161
- ): Promise<(thread: AgentThreadView) => (AgentThreadComputer & { online: boolean }) | undefined> {
166
+ ): Promise<(thread: AgentThreadView) => ThreadComputerView> {
167
+ // A thread that moved may still have commands running where it was.
162
168
  const owned = (thread: AgentThreadView) =>
163
- thread.computer !== undefined && principalsEqual(thread.ownerPrincipal, viewer)
169
+ (thread.computer !== undefined || thread.movedAt !== undefined) &&
170
+ principalsEqual(thread.ownerPrincipal, viewer)
164
171
  const live =
165
172
  host.storage.agents && threads.some(owned)
166
173
  ? await host.storage.agents.computers.listLive({
@@ -170,13 +177,51 @@ async function computerPlaces(
170
177
  })
171
178
  : []
172
179
  return (thread) => {
180
+ if (!owned(thread)) return {}
181
+
182
+ // Its background commands, from any of its owner's sixb: a command started in one folder runs
183
+ // on there once the thread moved to another, or to the cloud. And which of them a stop is on.
184
+ const backgroundCommands = live.flatMap((session) =>
185
+ (session.backgroundCommands ?? [])
186
+ .filter((command) => command.threadId === thread.id)
187
+ .map((command) => {
188
+ const stopping =
189
+ command.status === "running" &&
190
+ (session.stopRequests ?? []).some((ref) => sameBackgroundCommand(command, ref))
191
+ return stopping ? { ...command, stopping } : command
192
+ })
193
+ )
194
+
173
195
  const computer = thread.computer
174
- if (!computer || !owned(thread)) return undefined
175
- const online = live.some((session) => sameComputerPlace(session.computer, computer))
176
- return { ...computer, online }
196
+ const online =
197
+ computer !== undefined &&
198
+ live.some((session) => sameComputerPlace(session.computer, computer))
199
+ return {
200
+ ...(computer ? { computer: { ...computer, online } } : {}),
201
+ ...(backgroundCommands.length > 0 ? { backgroundCommands } : {}),
202
+ }
177
203
  }
178
204
  }
179
205
 
206
+ interface ThreadComputerView {
207
+ readonly computer?: AgentThreadComputer & { readonly online: boolean }
208
+ readonly backgroundCommands?: readonly (AgentComputerBackgroundCommand & {
209
+ readonly stopping?: boolean
210
+ })[]
211
+ }
212
+
213
+ /** Whether a reported background command is the one `ref` names: by its start, as ids repeat. */
214
+ export function sameBackgroundCommand(
215
+ command: AgentBackgroundCommandRef,
216
+ ref: AgentBackgroundCommandRef
217
+ ): boolean {
218
+ return (
219
+ command.threadId === ref.threadId &&
220
+ command.id === ref.id &&
221
+ command.startedAt === ref.startedAt
222
+ )
223
+ }
224
+
180
225
  function serializeMessage(
181
226
  message: AgentMessageRecord,
182
227
  annotations: readonly AgentRunDiagnostic[] = [],
@@ -1,8 +1,10 @@
1
1
  import type { SixbHostView } from "@sixb/core"
2
2
  import { parseArtifactAddress } from "@sixb/core/artifacts"
3
+ import { annotateBoard } from "@sixb/core/artifacts/live"
3
4
  import {
4
5
  ARTIFACT_FRAME_ROUTE_PREFIX,
5
6
  FRAME_ASSETS,
7
+ FRAME_REFERENCE_PATH,
6
8
  FRAME_REFERENCE_PREFIX,
7
9
  frameEntries,
8
10
  frameLayout,
@@ -11,6 +13,11 @@ import {
11
13
  rewriteFrameReferences,
12
14
  } from "@sixb/core/internal/artifacts/frames"
13
15
  import { openFileRef } from "@sixb/core/internal/blob-storage"
16
+ import type {
17
+ ArtifactFrameTarget,
18
+ ArtifactStorage,
19
+ ArtifactVersionRecord,
20
+ } from "@sixb/core/storage"
14
21
  import type { Elysia } from "elysia"
15
22
  import { frameContentSecurityPolicy } from "../artifacts/frame"
16
23
  import type { ResolvedSixbApiBrowserPolicy } from "../auth/browser-origin"
@@ -24,7 +31,8 @@ interface FrameContext {
24
31
  /**
25
32
  * Serves a version's files to its sandboxed frame, under the token a frame link carries: the token
26
33
  * 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
34
+ * which are served beside the files. A canvas's board asked for with `?sixb-edit` is served for
35
+ * editing: its static elements marked with their addresses. Hidden from OpenAPI: clients receive frame links, they
28
36
  * never build them.
29
37
  */
30
38
  export function registerArtifactFrameRoutes(
@@ -84,21 +92,16 @@ async function frameResponse(
84
92
  }
85
93
  let lent = false
86
94
  if (path?.startsWith(FRAME_REFERENCE_PREFIX)) {
87
- // A file another artifact lends this one: only one its frame was issued with, at that version.
88
- const match = /^([^/@]+)@(\d+)\/(.+)$/.exec(path.slice(FRAME_REFERENCE_PREFIX.length))
95
+ // A file another artifact lends this one: only one its frame was issued with. A pinned
96
+ // address shows its created version; an unpinned one the lender's latest, as it is now.
97
+ const match = FRAME_REFERENCE_PATH.exec(path.slice(FRAME_REFERENCE_PREFIX.length))
89
98
  const target = frame.targets.find(
90
99
  (candidate) =>
91
100
  candidate.artifactId === match?.[1] &&
92
- candidate.version === Number(match?.[2]) &&
101
+ String(candidate.version) === match?.[2] &&
93
102
  parseArtifactAddress(candidate.address)?.path === match?.[3]
94
103
  )
95
- const lender = target
96
- ? await storage.getVersion({
97
- projectId: host.id,
98
- artifactId: target.artifactId,
99
- version: target.version,
100
- })
101
- : null
104
+ const lender = target ? await lenderVersion(storage, host.id, target) : null
102
105
  if (!lender || !match) return notFound()
103
106
  version = lender
104
107
  path = match[3] ?? null
@@ -115,8 +118,18 @@ async function frameResponse(
115
118
  headers.set("cache-control", "private, no-cache")
116
119
  if (options.head) return new Response(null, { headers })
117
120
  const text = await new Response(opened.body).text()
121
+
122
+ // A canvas's board served for editing has its static elements marked with their addresses,
123
+ // for the runtime to report and edit them by.
124
+ const editing =
125
+ version.outline.kind === "canvas" && new URL(request.url).searchParams.has("sixb-edit")
126
+ const source = editing ? annotateBoard(text) : text
118
127
  return new Response(
119
- injectFrameAssets(rewriteFrameReferences(text, frame.targets, file.path), layout, file.path),
128
+ injectFrameAssets(
129
+ rewriteFrameReferences(source, frame.targets, file.path),
130
+ layout,
131
+ file.path
132
+ ),
120
133
  { headers }
121
134
  )
122
135
  }
@@ -135,6 +148,21 @@ async function frameResponse(
135
148
  return response
136
149
  }
137
150
 
151
+ async function lenderVersion(
152
+ storage: ArtifactStorage,
153
+ projectId: string,
154
+ target: ArtifactFrameTarget
155
+ ): Promise<ArtifactVersionRecord | null> {
156
+ const { artifactId } = target
157
+ const version =
158
+ target.version === "latest"
159
+ ? (await storage.get({ projectId, id: artifactId }))?.latestVersion
160
+ : target.version
161
+ if (version === undefined) return null
162
+
163
+ return storage.getVersion({ projectId, artifactId, version })
164
+ }
165
+
138
166
  function decodePath(raw: string | undefined): string | null {
139
167
  try {
140
168
  return decodeURIComponent(raw ?? "")