@sixb/server 0.2.4 → 0.2.6
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.
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +877 -89
- package/dist/index.js.map +26 -25
- package/dist/live/room.d.ts +2 -0
- package/dist/live/room.d.ts.map +1 -1
- package/dist/registerRoutes.d.ts +1 -0
- package/dist/registerRoutes.d.ts.map +1 -1
- package/dist/routes/agent-approvals.d.ts +22 -0
- package/dist/routes/agent-approvals.d.ts.map +1 -1
- package/dist/routes/agent-computers.d.ts +36 -0
- package/dist/routes/agent-computers.d.ts.map +1 -1
- package/dist/routes/agent-runners.d.ts +5 -1
- package/dist/routes/agent-runners.d.ts.map +1 -1
- package/dist/routes/agent-thread-reads.d.ts +82 -0
- package/dist/routes/agent-thread-reads.d.ts.map +1 -0
- package/dist/routes/agents.d.ts +1760 -86
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/ai-accounting.d.ts.map +1 -1
- package/dist/routes/artifact-frames.d.ts +3 -3
- package/dist/routes/artifact-frames.d.ts.map +1 -1
- package/dist/routes/artifacts.d.ts +287 -21
- package/dist/routes/artifacts.d.ts.map +1 -1
- package/dist/routes/auth.d.ts +7 -7
- package/dist/routes/events.d.ts +4 -4
- package/dist/routes/links.d.ts +8 -0
- package/dist/routes/links.d.ts.map +1 -1
- package/dist/routes/model-generations.d.ts +6 -0
- package/dist/routes/model-generations.d.ts.map +1 -1
- package/dist/routes/objects.d.ts +8 -0
- package/dist/routes/objects.d.ts.map +1 -1
- package/dist/routes/observed-agent-threads.d.ts +22 -0
- package/dist/routes/observed-agent-threads.d.ts.map +1 -1
- package/dist/routes/projections.d.ts +2 -0
- package/dist/routes/projections.d.ts.map +1 -1
- package/dist/routes/status.d.ts +4 -1
- package/dist/routes/status.d.ts.map +1 -1
- package/dist/routes/syncs.d.ts +175 -12
- package/dist/routes/syncs.d.ts.map +1 -1
- package/dist/routes/workflows.d.ts +6 -6
- package/dist/routes/ws/agents.d.ts.map +1 -1
- package/dist/routes/ws/events.d.ts +6 -6
- package/dist/schemas/activity.d.ts +4 -4
- package/dist/schemas/agents.d.ts +7697 -262
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/ai-accounting.d.ts +3 -0
- package/dist/schemas/ai-accounting.d.ts.map +1 -1
- package/dist/schemas/artifacts.d.ts +676 -36
- package/dist/schemas/artifacts.d.ts.map +1 -1
- package/dist/schemas/auth.d.ts +8 -8
- package/dist/schemas/common.d.ts.map +1 -1
- package/dist/schemas/events.d.ts +36 -24
- package/dist/schemas/events.d.ts.map +1 -1
- package/dist/schemas/lineage.d.ts +112 -0
- package/dist/schemas/lineage.d.ts.map +1 -1
- package/dist/schemas/models.d.ts +46 -0
- package/dist/schemas/models.d.ts.map +1 -1
- package/dist/schemas/projections.d.ts +11 -0
- package/dist/schemas/projections.d.ts.map +1 -1
- package/dist/schemas/syncs.d.ts +724 -25
- package/dist/schemas/syncs.d.ts.map +1 -1
- package/dist/schemas/workflows.d.ts +22 -22
- package/dist/server.d.ts +16 -1
- package/dist/server.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +6 -1
- package/src/live/README.md +9 -6
- package/src/live/room.ts +16 -8
- package/src/registerRoutes.ts +4 -1
- package/src/routes/agent-computers.ts +7 -6
- package/src/routes/agent-runners.ts +15 -4
- package/src/routes/agent-thread-reads.ts +67 -0
- package/src/routes/agents.ts +331 -20
- package/src/routes/ai-accounting.ts +1 -0
- package/src/routes/artifact-frames.ts +22 -9
- package/src/routes/artifacts.ts +124 -3
- package/src/routes/model-generations.ts +1 -1
- package/src/routes/observed-agent-threads.ts +3 -4
- package/src/routes/status.ts +18 -1
- package/src/routes/syncs.ts +135 -8
- package/src/routes/ws/agents.ts +43 -3
- package/src/schemas/agents.ts +148 -12
- package/src/schemas/ai-accounting.ts +12 -0
- package/src/schemas/artifacts.ts +66 -1
- package/src/schemas/common.ts +15 -9
- package/src/schemas/events.ts +1 -0
- package/src/schemas/models.ts +10 -0
- package/src/schemas/projections.ts +1 -0
- package/src/schemas/syncs.ts +63 -1
- package/src/server.ts +208 -14
package/src/routes/agents.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
type AgentMessagePart,
|
|
2
3
|
AgentRequestError,
|
|
3
4
|
type AgentRequestErrorCode,
|
|
4
5
|
type AgentRunView,
|
|
@@ -20,6 +21,7 @@ import {
|
|
|
20
21
|
type AgentBackgroundCommandRef,
|
|
21
22
|
type AgentComputerBackgroundCommand,
|
|
22
23
|
type AgentContextCheckpointRecord,
|
|
24
|
+
type AgentInboxItemRecord,
|
|
23
25
|
type AgentMessageRecord,
|
|
24
26
|
type AgentRunDiagnostic,
|
|
25
27
|
type AgentStorage,
|
|
@@ -48,9 +50,11 @@ import { OPENAPI_TAGS } from "../openapi/tags"
|
|
|
48
50
|
import {
|
|
49
51
|
AddAgentThreadParticipantsBodySchema,
|
|
50
52
|
AgentDescriptorSchema,
|
|
53
|
+
AgentInboxItemSchema,
|
|
54
|
+
AgentInboxListResponseSchema,
|
|
51
55
|
AgentMessageFileContentParamsSchema,
|
|
52
56
|
AgentMessageListResponseSchema,
|
|
53
|
-
AgentMessageSchema,
|
|
57
|
+
type AgentMessageSchema,
|
|
54
58
|
AgentMessagesQuerySchema,
|
|
55
59
|
AgentRequestErrorResponseSchema,
|
|
56
60
|
AgentRunListQuerySchema,
|
|
@@ -59,6 +63,7 @@ import {
|
|
|
59
63
|
AgentRunSchema,
|
|
60
64
|
AgentThreadContextQuerySchema,
|
|
61
65
|
AgentThreadContextSchema,
|
|
66
|
+
AgentThreadInboxParamsSchema,
|
|
62
67
|
AgentThreadListQuerySchema,
|
|
63
68
|
AgentThreadListResponseSchema,
|
|
64
69
|
AgentThreadParamsSchema,
|
|
@@ -68,9 +73,13 @@ import {
|
|
|
68
73
|
CancelAgentRunResponseSchema,
|
|
69
74
|
CreateAgentThreadBodySchema,
|
|
70
75
|
CreateAgentThreadResponseSchema,
|
|
76
|
+
EditAgentMessageBodySchema,
|
|
77
|
+
EditAgentMessageResponseSchema,
|
|
71
78
|
PostAgentMessageBodySchema,
|
|
72
79
|
PostAgentMessageResponseSchema,
|
|
73
80
|
RetryAgentRunResponseSchema,
|
|
81
|
+
UpdateAgentInboxItemBodySchema,
|
|
82
|
+
UpdateAgentInboxItemResponseSchema,
|
|
74
83
|
} from "../schemas/agents"
|
|
75
84
|
import { AiUsageLimitErrorResponseSchema, ErrorResponseSchema } from "../schemas/common"
|
|
76
85
|
import { FileContentQuerySchema } from "../schemas/files"
|
|
@@ -141,6 +150,23 @@ export async function serializeThreads(
|
|
|
141
150
|
messageCount: thread.messageCount,
|
|
142
151
|
createdAt: toIsoString(thread.createdAt),
|
|
143
152
|
updatedAt: toIsoString(thread.updatedAt),
|
|
153
|
+
read: thread.read && {
|
|
154
|
+
threadId: thread.read.threadId,
|
|
155
|
+
throughSeq: thread.read.throughSeq,
|
|
156
|
+
headSeq: thread.read.headSeq,
|
|
157
|
+
unread: thread.read.unread,
|
|
158
|
+
readAt: thread.read.readAt ? toIsoString(thread.read.readAt) : undefined,
|
|
159
|
+
},
|
|
160
|
+
lastRun: thread.lastRun && {
|
|
161
|
+
id: thread.lastRun.id,
|
|
162
|
+
status: thread.lastRun.status,
|
|
163
|
+
finishReason: thread.lastRun.finishReason,
|
|
164
|
+
errorCode: thread.lastRun.errorCode,
|
|
165
|
+
completedAt: thread.lastRun.completedAt
|
|
166
|
+
? toIsoString(thread.lastRun.completedAt)
|
|
167
|
+
: undefined,
|
|
168
|
+
requestedBy: thread.lastRun.requestedBy,
|
|
169
|
+
},
|
|
144
170
|
})
|
|
145
171
|
)
|
|
146
172
|
}
|
|
@@ -222,12 +248,16 @@ export function sameBackgroundCommand(
|
|
|
222
248
|
)
|
|
223
249
|
}
|
|
224
250
|
|
|
251
|
+
/**
|
|
252
|
+
* A message as the API returns it, unchecked: the route's response schema checks it once, and drops
|
|
253
|
+
* what the schema does not name. Parsed here too, a thread's messages were checked three times.
|
|
254
|
+
*/
|
|
225
255
|
function serializeMessage(
|
|
226
256
|
message: AgentMessageRecord,
|
|
227
257
|
annotations: readonly AgentRunDiagnostic[] = [],
|
|
228
258
|
checkpoint?: AgentContextCheckpointRecord
|
|
229
|
-
):
|
|
230
|
-
return
|
|
259
|
+
): z.infer<typeof AgentMessageSchema> {
|
|
260
|
+
return {
|
|
231
261
|
id: message.id,
|
|
232
262
|
projectId: message.projectId,
|
|
233
263
|
threadId: message.threadId,
|
|
@@ -235,7 +265,7 @@ function serializeMessage(
|
|
|
235
265
|
role: message.role,
|
|
236
266
|
authorPrincipal: message.authorPrincipal,
|
|
237
267
|
seq: message.seq,
|
|
238
|
-
parts: message.parts,
|
|
268
|
+
parts: message.parts.map(withoutReplayState),
|
|
239
269
|
annotations,
|
|
240
270
|
compaction: checkpoint
|
|
241
271
|
? {
|
|
@@ -249,10 +279,52 @@ function serializeMessage(
|
|
|
249
279
|
contentVersion: message.contentVersion,
|
|
250
280
|
createdAt: toIsoString(message.createdAt),
|
|
251
281
|
completedAt: message.completedAt ? toIsoString(message.completedAt) : undefined,
|
|
282
|
+
} as z.infer<typeof AgentMessageSchema>
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* A part without what only replays the conversation to its model: a provider's opaque state and
|
|
287
|
+
* metadata, such as encrypted reasoning, which no reader shows and which made up some 40% of a long
|
|
288
|
+
* thread's messages. A provider-state part stays, with no data, so each part keeps its index for
|
|
289
|
+
* the `/parts/<index>/...` paths files are read at.
|
|
290
|
+
*/
|
|
291
|
+
function withoutReplayState(part: AgentMessagePart): AgentMessagePart {
|
|
292
|
+
if (part.type === "provider-state") return { ...part, data: null }
|
|
293
|
+
if (!("providerMetadata" in part) || part.providerMetadata === undefined) return part
|
|
294
|
+
const { providerMetadata: _replay, ...shown } = part
|
|
295
|
+
return shown as AgentMessagePart
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export function serializeAgentInboxItem(
|
|
299
|
+
item: AgentInboxItemRecord
|
|
300
|
+
): ReturnType<typeof AgentInboxItemSchema.parse> {
|
|
301
|
+
return AgentInboxItemSchema.parse({
|
|
302
|
+
id: item.id,
|
|
303
|
+
projectId: item.projectId,
|
|
304
|
+
threadId: item.threadId,
|
|
305
|
+
messageId: item.messageId,
|
|
306
|
+
seq: item.seq,
|
|
307
|
+
authorPrincipal: item.authorPrincipal,
|
|
308
|
+
mode: item.mode,
|
|
309
|
+
parts: item.parts,
|
|
310
|
+
spec: item.spec,
|
|
311
|
+
timeZone: item.timeZone,
|
|
312
|
+
locale: item.locale,
|
|
313
|
+
immediate: item.immediate === true ? true : undefined,
|
|
314
|
+
replacesMessageId: item.replacesMessageId,
|
|
315
|
+
createdAt: toIsoString(item.createdAt),
|
|
316
|
+
updatedAt: toIsoString(item.updatedAt),
|
|
252
317
|
})
|
|
253
318
|
}
|
|
254
319
|
|
|
255
|
-
|
|
320
|
+
/**
|
|
321
|
+
* A run as the API returns it. `ownerReads`: its thread's owner reads it, and alone sees the folder
|
|
322
|
+
* on their computer it runs in, as with the thread's own `computer`.
|
|
323
|
+
*/
|
|
324
|
+
export function serializeAgentRun(
|
|
325
|
+
run: AgentRunView,
|
|
326
|
+
{ ownerReads = false }: { readonly ownerReads?: boolean } = {}
|
|
327
|
+
): ReturnType<typeof AgentRunSchema.parse> {
|
|
256
328
|
return AgentRunSchema.parse({
|
|
257
329
|
id: run.id,
|
|
258
330
|
projectId: run.projectId,
|
|
@@ -267,6 +339,7 @@ export function serializeAgentRun(run: AgentRunView): ReturnType<typeof AgentRun
|
|
|
267
339
|
reasoning: run.spec?.reasoning,
|
|
268
340
|
approvalMode: run.spec?.approvalMode,
|
|
269
341
|
runsOn: run.kind === "conversation" ? run.spec?.runsOn : undefined,
|
|
342
|
+
computer: ownerReads && run.kind === "conversation" ? run.spec?.computer : undefined,
|
|
270
343
|
modelId: run.modelId,
|
|
271
344
|
finishReason: run.finishReason,
|
|
272
345
|
usage: run.usage,
|
|
@@ -301,6 +374,27 @@ async function getAgentMessageFileContentThread(params: {
|
|
|
301
374
|
return params.authState.sixb.agent.threads.getById(params.threadId)
|
|
302
375
|
}
|
|
303
376
|
|
|
377
|
+
/**
|
|
378
|
+
* An inbox route's error: a message a turn already read, or an inbox already full, is a conflict.
|
|
379
|
+
* The provider's message names the run, so it stays out of the answer.
|
|
380
|
+
*/
|
|
381
|
+
function handleAgentInboxRouteError(
|
|
382
|
+
error: unknown,
|
|
383
|
+
set: { status?: number | string; headers?: unknown }
|
|
384
|
+
):
|
|
385
|
+
| ReturnType<typeof handleAgentRouteError>
|
|
386
|
+
| { readonly error: string; readonly code: "invalid_state" | "inbox_limit" } {
|
|
387
|
+
if (error instanceof AgentStorageError && error.code === "invalid_state") {
|
|
388
|
+
set.status = 409
|
|
389
|
+
return { error: "A turn already read this message", code: error.code }
|
|
390
|
+
}
|
|
391
|
+
if (error instanceof AgentStorageError && error.code === "inbox_limit") {
|
|
392
|
+
set.status = 409
|
|
393
|
+
return { error: "Too many messages are waiting in this conversation", code: error.code }
|
|
394
|
+
}
|
|
395
|
+
return handleAgentRouteError(error, set)
|
|
396
|
+
}
|
|
397
|
+
|
|
304
398
|
export function handleAgentRouteError(
|
|
305
399
|
error: unknown,
|
|
306
400
|
set: { status?: number | string; headers?: unknown }
|
|
@@ -326,12 +420,14 @@ export function handleAgentRouteError(
|
|
|
326
420
|
// Core performs visibility checks before workspace state transitions.
|
|
327
421
|
switch (error.code) {
|
|
328
422
|
case "agent_not_found":
|
|
423
|
+
case "message_not_found":
|
|
329
424
|
case "run_not_found":
|
|
330
425
|
case "thread_not_found":
|
|
331
426
|
case "approval_not_found":
|
|
332
427
|
set.status = 404
|
|
333
428
|
break
|
|
334
429
|
case "active_run_exists":
|
|
430
|
+
case "message_not_editable":
|
|
335
431
|
case "thread_not_conversation":
|
|
336
432
|
case "run_not_retryable":
|
|
337
433
|
case "run_not_active":
|
|
@@ -341,6 +437,7 @@ export function handleAgentRouteError(
|
|
|
341
437
|
set.status = 409
|
|
342
438
|
break
|
|
343
439
|
case "authority_not_inheritable":
|
|
440
|
+
case "not_message_author":
|
|
344
441
|
case "not_thread_owner":
|
|
345
442
|
case "not_run_requester":
|
|
346
443
|
set.status = 403
|
|
@@ -845,6 +942,43 @@ export function registerAgentRoutes(app: Elysia, host: SixbHostView) {
|
|
|
845
942
|
},
|
|
846
943
|
}
|
|
847
944
|
)
|
|
945
|
+
.post(
|
|
946
|
+
"/api/agent-threads/:threadId/sandbox/restore",
|
|
947
|
+
async (context) => {
|
|
948
|
+
try {
|
|
949
|
+
const sixb = requireRequestSixb(context)
|
|
950
|
+
const thread = await sixb.agent.threads.restoreSandbox(
|
|
951
|
+
context.params.threadId,
|
|
952
|
+
context.body
|
|
953
|
+
)
|
|
954
|
+
return serializeThread(host, thread, requestActor(sixb))
|
|
955
|
+
} catch (error) {
|
|
956
|
+
if (error instanceof AgentStorageError && error.code === "invalid_state") {
|
|
957
|
+
context.set.status = 409
|
|
958
|
+
return { error: "Sandbox state changed or a run is active. Reload and try again." }
|
|
959
|
+
}
|
|
960
|
+
return handleAgentRouteError(error, context.set)
|
|
961
|
+
}
|
|
962
|
+
},
|
|
963
|
+
{
|
|
964
|
+
params: AgentThreadParamsSchema,
|
|
965
|
+
body: z.object({ expectedSandboxName: z.string().min(1) }).strict(),
|
|
966
|
+
response: {
|
|
967
|
+
200: AgentThreadSchema,
|
|
968
|
+
400: ErrorResponseSchema,
|
|
969
|
+
403: AgentRequestErrorResponseSchema,
|
|
970
|
+
404: ErrorResponseSchema,
|
|
971
|
+
409: AgentRequestErrorResponseSchema,
|
|
972
|
+
},
|
|
973
|
+
detail: {
|
|
974
|
+
summary:
|
|
975
|
+
"Explicitly go on in the workspace a failed save left, with its files as they were",
|
|
976
|
+
operationId: "restoreAgentThreadSandbox",
|
|
977
|
+
tags: [OPENAPI_TAGS.agentThreads.name],
|
|
978
|
+
security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT,
|
|
979
|
+
},
|
|
980
|
+
}
|
|
981
|
+
)
|
|
848
982
|
.get(
|
|
849
983
|
"/api/agent-threads/:threadId/messages",
|
|
850
984
|
async (context) => {
|
|
@@ -873,9 +1007,8 @@ export function registerAgentRoutes(app: Elysia, host: SixbHostView) {
|
|
|
873
1007
|
}
|
|
874
1008
|
|
|
875
1009
|
const parsed = AgentMessagesQuerySchema.parse(query)
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
)
|
|
1010
|
+
// The response schema checks the page once, as it leaves.
|
|
1011
|
+
return await readThreadMessages(host, storage, thread, parsed)
|
|
879
1012
|
} catch (error) {
|
|
880
1013
|
return handleAgentRouteError(error, set)
|
|
881
1014
|
}
|
|
@@ -959,14 +1092,19 @@ export function registerAgentRoutes(app: Elysia, host: SixbHostView) {
|
|
|
959
1092
|
context: parsed.context,
|
|
960
1093
|
messageId: parsed.messageId,
|
|
961
1094
|
}
|
|
962
|
-
const
|
|
1095
|
+
const sent = await sixb.agent.runs.send({
|
|
1096
|
+
...requestInput,
|
|
1097
|
+
delivery: parsed.delivery,
|
|
1098
|
+
})
|
|
963
1099
|
|
|
964
1100
|
set.status = 202
|
|
965
|
-
return PostAgentMessageResponseSchema.parse(
|
|
966
|
-
|
|
967
|
-
|
|
1101
|
+
return PostAgentMessageResponseSchema.parse(
|
|
1102
|
+
sent.kind === "turn"
|
|
1103
|
+
? { run: serializeAgentRun(sent.run) }
|
|
1104
|
+
: { item: serializeAgentInboxItem(sent.item) }
|
|
1105
|
+
)
|
|
968
1106
|
} catch (error) {
|
|
969
|
-
return
|
|
1107
|
+
return handleAgentInboxRouteError(error, set)
|
|
970
1108
|
}
|
|
971
1109
|
},
|
|
972
1110
|
{
|
|
@@ -990,6 +1128,172 @@ export function registerAgentRoutes(app: Elysia, host: SixbHostView) {
|
|
|
990
1128
|
},
|
|
991
1129
|
}
|
|
992
1130
|
)
|
|
1131
|
+
.get(
|
|
1132
|
+
"/api/agent-threads/:threadId/inbox",
|
|
1133
|
+
async (context) => {
|
|
1134
|
+
const { params, set } = context
|
|
1135
|
+
const sixb = requireRequestSixb(context)
|
|
1136
|
+
try {
|
|
1137
|
+
if (!host.storage.agents) {
|
|
1138
|
+
return missingAgentStorageResponse(set)
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
const items = await sixb.agent.inbox.list(params.threadId)
|
|
1142
|
+
return AgentInboxListResponseSchema.parse({
|
|
1143
|
+
items: items.map(serializeAgentInboxItem),
|
|
1144
|
+
})
|
|
1145
|
+
} catch (error) {
|
|
1146
|
+
return handleAgentRouteError(error, set)
|
|
1147
|
+
}
|
|
1148
|
+
},
|
|
1149
|
+
{
|
|
1150
|
+
params: AgentThreadParamsSchema,
|
|
1151
|
+
response: {
|
|
1152
|
+
200: AgentInboxListResponseSchema,
|
|
1153
|
+
400: AgentRequestErrorResponseSchema,
|
|
1154
|
+
404: ErrorResponseSchema,
|
|
1155
|
+
501: ErrorResponseSchema,
|
|
1156
|
+
},
|
|
1157
|
+
detail: {
|
|
1158
|
+
summary: "List agent thread inbox messages",
|
|
1159
|
+
tags: [OPENAPI_TAGS.agentThreads.name],
|
|
1160
|
+
operationId: "listAgentThreadInbox",
|
|
1161
|
+
security: accessTokenSecurityRequirement("listAgentThreadInbox"),
|
|
1162
|
+
},
|
|
1163
|
+
}
|
|
1164
|
+
)
|
|
1165
|
+
.patch(
|
|
1166
|
+
"/api/agent-threads/:threadId/inbox/:itemId",
|
|
1167
|
+
async (context) => {
|
|
1168
|
+
const { params, body, set } = context
|
|
1169
|
+
const sixb = requireRequestSixb(context)
|
|
1170
|
+
try {
|
|
1171
|
+
if (!host.storage.agents) {
|
|
1172
|
+
return missingAgentStorageResponse(set)
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
const parsed = UpdateAgentInboxItemBodySchema.parse(body)
|
|
1176
|
+
const item = await sixb.agent.inbox.update(params.threadId, params.itemId, parsed)
|
|
1177
|
+
return UpdateAgentInboxItemResponseSchema.parse({
|
|
1178
|
+
item: serializeAgentInboxItem(item),
|
|
1179
|
+
})
|
|
1180
|
+
} catch (error) {
|
|
1181
|
+
return handleAgentInboxRouteError(error, set)
|
|
1182
|
+
}
|
|
1183
|
+
},
|
|
1184
|
+
{
|
|
1185
|
+
params: AgentThreadInboxParamsSchema,
|
|
1186
|
+
body: UpdateAgentInboxItemBodySchema,
|
|
1187
|
+
response: {
|
|
1188
|
+
200: UpdateAgentInboxItemResponseSchema,
|
|
1189
|
+
400: AgentRequestErrorResponseSchema,
|
|
1190
|
+
403: AgentRequestErrorResponseSchema,
|
|
1191
|
+
404: ErrorResponseSchema,
|
|
1192
|
+
409: AgentRequestErrorResponseSchema,
|
|
1193
|
+
501: ErrorResponseSchema,
|
|
1194
|
+
},
|
|
1195
|
+
detail: {
|
|
1196
|
+
summary: "Update a waiting agent thread message",
|
|
1197
|
+
tags: [OPENAPI_TAGS.agentThreads.name],
|
|
1198
|
+
operationId: "updateAgentThreadInboxItem",
|
|
1199
|
+
security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT,
|
|
1200
|
+
},
|
|
1201
|
+
}
|
|
1202
|
+
)
|
|
1203
|
+
.delete(
|
|
1204
|
+
"/api/agent-threads/:threadId/inbox/:itemId",
|
|
1205
|
+
async (context) => {
|
|
1206
|
+
const { params, set } = context
|
|
1207
|
+
const sixb = requireRequestSixb(context)
|
|
1208
|
+
try {
|
|
1209
|
+
if (!host.storage.agents) {
|
|
1210
|
+
return missingAgentStorageResponse(set)
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
await sixb.agent.inbox.remove(params.threadId, params.itemId)
|
|
1214
|
+
|
|
1215
|
+
set.status = 204
|
|
1216
|
+
return
|
|
1217
|
+
} catch (error) {
|
|
1218
|
+
return handleAgentInboxRouteError(error, set)
|
|
1219
|
+
}
|
|
1220
|
+
},
|
|
1221
|
+
{
|
|
1222
|
+
params: AgentThreadInboxParamsSchema,
|
|
1223
|
+
response: {
|
|
1224
|
+
204: z.void(),
|
|
1225
|
+
400: AgentRequestErrorResponseSchema,
|
|
1226
|
+
403: AgentRequestErrorResponseSchema,
|
|
1227
|
+
404: ErrorResponseSchema,
|
|
1228
|
+
409: AgentRequestErrorResponseSchema,
|
|
1229
|
+
501: ErrorResponseSchema,
|
|
1230
|
+
},
|
|
1231
|
+
detail: {
|
|
1232
|
+
summary: "Withdraw a waiting agent thread message",
|
|
1233
|
+
tags: [OPENAPI_TAGS.agentThreads.name],
|
|
1234
|
+
operationId: "withdrawAgentThreadInboxItem",
|
|
1235
|
+
security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT,
|
|
1236
|
+
},
|
|
1237
|
+
}
|
|
1238
|
+
)
|
|
1239
|
+
.post(
|
|
1240
|
+
"/api/agent-threads/:threadId/messages/:messageId/edit",
|
|
1241
|
+
async (context) => {
|
|
1242
|
+
const { params, body, set } = context
|
|
1243
|
+
const sixb = requireRequestSixb(context)
|
|
1244
|
+
try {
|
|
1245
|
+
const storage = host.storage.agents
|
|
1246
|
+
if (!storage) {
|
|
1247
|
+
return missingAgentStorageResponse(set)
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
const parsed = EditAgentMessageBodySchema.parse(body)
|
|
1251
|
+
const result = await sixb.agent.runs.editMessage({
|
|
1252
|
+
threadId: params.threadId,
|
|
1253
|
+
messageId: params.messageId,
|
|
1254
|
+
text: parsed.text,
|
|
1255
|
+
model: parsed.model,
|
|
1256
|
+
reasoning: parsed.reasoning,
|
|
1257
|
+
timeZone: parsed.timeZone,
|
|
1258
|
+
locale: parsed.locale,
|
|
1259
|
+
approvalMode: parsed.approvalMode,
|
|
1260
|
+
attachments: parsed.attachments as readonly FileRef[] | undefined,
|
|
1261
|
+
context: parsed.context,
|
|
1262
|
+
nextMessageId: parsed.nextMessageId,
|
|
1263
|
+
})
|
|
1264
|
+
|
|
1265
|
+
set.status = 202
|
|
1266
|
+
return EditAgentMessageResponseSchema.parse(
|
|
1267
|
+
result.kind === "turn"
|
|
1268
|
+
? { run: serializeAgentRun(result.run) }
|
|
1269
|
+
: { item: serializeAgentInboxItem(result.item) }
|
|
1270
|
+
)
|
|
1271
|
+
} catch (error) {
|
|
1272
|
+
return handleAgentInboxRouteError(error, set)
|
|
1273
|
+
}
|
|
1274
|
+
},
|
|
1275
|
+
{
|
|
1276
|
+
params: AgentMessageFileContentParamsSchema,
|
|
1277
|
+
body: EditAgentMessageBodySchema,
|
|
1278
|
+
response: {
|
|
1279
|
+
202: EditAgentMessageResponseSchema,
|
|
1280
|
+
400: AgentRequestErrorResponseSchema,
|
|
1281
|
+
403: AgentRequestErrorResponseSchema,
|
|
1282
|
+
404: ErrorResponseSchema,
|
|
1283
|
+
409: AgentRequestErrorResponseSchema,
|
|
1284
|
+
429: AiUsageLimitErrorResponseSchema,
|
|
1285
|
+
501: ErrorResponseSchema,
|
|
1286
|
+
},
|
|
1287
|
+
detail: {
|
|
1288
|
+
summary: "Edit an agent thread message and restart from that turn",
|
|
1289
|
+
description:
|
|
1290
|
+
"Replaces a user-authored message in place, removes any messages and compaction summaries from that turn onward, and starts a new turn from the edited message. While a turn runs, the edit stops it and waits in the thread's inbox: the turn's end rewinds the thread and starts the edited message.",
|
|
1291
|
+
tags: [OPENAPI_TAGS.agentThreads.name],
|
|
1292
|
+
operationId: "editAgentThreadMessage",
|
|
1293
|
+
security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT,
|
|
1294
|
+
},
|
|
1295
|
+
}
|
|
1296
|
+
)
|
|
993
1297
|
.post(
|
|
994
1298
|
"/api/agent-threads/:threadId/cancel",
|
|
995
1299
|
async (context) => {
|
|
@@ -1205,19 +1509,26 @@ export function registerAgentRoutes(app: Elysia, host: SixbHostView) {
|
|
|
1205
1509
|
}
|
|
1206
1510
|
|
|
1207
1511
|
const parsed = AgentRunListQuerySchema.parse(query)
|
|
1208
|
-
const result = await
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1512
|
+
const [result, thread] = await Promise.all([
|
|
1513
|
+
sixb.agent.runs.listForThread(params.threadId, {
|
|
1514
|
+
statuses: parsed.status ? [parsed.status] : undefined,
|
|
1515
|
+
limit: parseOptionalInt(parsed.limit),
|
|
1516
|
+
offset: parseOptionalInt(parsed.offset),
|
|
1517
|
+
order: parsed.order,
|
|
1518
|
+
}),
|
|
1519
|
+
storage.threads.getById({ projectId: host.id, id: params.threadId }),
|
|
1520
|
+
])
|
|
1214
1521
|
if (!result) {
|
|
1215
1522
|
set.status = 404
|
|
1216
1523
|
return { error: "Agent thread not found" }
|
|
1217
1524
|
}
|
|
1218
1525
|
|
|
1526
|
+
// Its owner reads where each turn ran, down to the folder: the app marks every move.
|
|
1527
|
+
const ownerReads =
|
|
1528
|
+
thread !== null && principalsEqual(thread.ownerPrincipal, requestActor(sixb))
|
|
1529
|
+
|
|
1219
1530
|
return AgentRunListResponseSchema.parse({
|
|
1220
|
-
runs: result.runs.map(serializeAgentRun),
|
|
1531
|
+
runs: result.runs.map((run) => serializeAgentRun(run, { ownerReads })),
|
|
1221
1532
|
hasMore: result.hasMore,
|
|
1222
1533
|
total: result.total,
|
|
1223
1534
|
})
|
|
@@ -348,6 +348,7 @@ export function registerAiAccountingRoutes(app: Elysia, host: SixbHostView) {
|
|
|
348
348
|
from: new Date(parsed.from),
|
|
349
349
|
to: new Date(parsed.to),
|
|
350
350
|
bucket: parsed.bucket,
|
|
351
|
+
...(parsed.timeZone === undefined ? {} : { timeZone: parsed.timeZone }),
|
|
351
352
|
providerId: parsed.providerId,
|
|
352
353
|
modelId: parsed.modelId,
|
|
353
354
|
...accountingFilters(parsed),
|
|
@@ -8,7 +8,9 @@ import {
|
|
|
8
8
|
FRAME_REFERENCE_PREFIX,
|
|
9
9
|
frameEntries,
|
|
10
10
|
frameLayout,
|
|
11
|
+
frozenDocumentHtml,
|
|
11
12
|
injectFrameAssets,
|
|
13
|
+
markDocumentSections,
|
|
12
14
|
resolveArtifactFrame,
|
|
13
15
|
rewriteFrameReferences,
|
|
14
16
|
} from "@sixb/core/internal/artifacts/frames"
|
|
@@ -31,9 +33,9 @@ interface FrameContext {
|
|
|
31
33
|
/**
|
|
32
34
|
* Serves a version's files to its sandboxed frame, under the token a frame link carries: the token
|
|
33
35
|
* is the credential, so the route is public. Each entry gets its layout's kit and the runtime,
|
|
34
|
-
* which are served beside the files. A canvas's board
|
|
35
|
-
* editing: its static elements marked with their addresses. Hidden from
|
|
36
|
-
* never build them.
|
|
36
|
+
* which are served beside the files. A canvas's board, or a designed document, asked for with
|
|
37
|
+
* `?sixb-edit` is served for editing: its static elements marked with their addresses. Hidden from
|
|
38
|
+
* OpenAPI: clients receive frame links, they never build them.
|
|
37
39
|
*/
|
|
38
40
|
export function registerArtifactFrameRoutes(
|
|
39
41
|
app: Elysia,
|
|
@@ -110,7 +112,7 @@ async function frameResponse(
|
|
|
110
112
|
const file = version.files.find((candidate) => candidate.path === path)
|
|
111
113
|
if (!file) return notFound()
|
|
112
114
|
|
|
113
|
-
const layout = frameLayout(version
|
|
115
|
+
const layout = frameLayout(version)
|
|
114
116
|
if (!lent && layout && frameEntries(version).includes(file.path)) {
|
|
115
117
|
const opened = await openFileRef(host.blobStorage, file.file)
|
|
116
118
|
if (!opened) return notFound()
|
|
@@ -119,16 +121,27 @@ async function frameResponse(
|
|
|
119
121
|
if (options.head) return new Response(null, { headers })
|
|
120
122
|
const text = await new Response(opened.body).text()
|
|
121
123
|
|
|
122
|
-
|
|
123
|
-
//
|
|
124
|
+
const { outline } = version
|
|
125
|
+
// A canvas's board, or a designed document, served for editing has its static elements
|
|
126
|
+
// marked with their addresses, for the runtime to report and edit them by.
|
|
124
127
|
const editing =
|
|
125
|
-
|
|
126
|
-
|
|
128
|
+
(outline.kind === "canvas" || outline.kind === "document") &&
|
|
129
|
+
new URL(request.url).searchParams.has("sixb-edit")
|
|
130
|
+
const marked = editing ? annotateBoard(text) : text
|
|
131
|
+
// A frozen designed document shows the values written in when it was frozen: its fields are
|
|
132
|
+
// served unmarked, so its frame reads none again.
|
|
133
|
+
const shown =
|
|
134
|
+
outline.kind === "document" && version.frozenAt ? frozenDocumentHtml(marked) : marked
|
|
135
|
+
// A designed document's headings carry their sections' slugs, to open it at one, and its
|
|
136
|
+
// runtime gets its paper, to cut it into pages.
|
|
137
|
+
const source =
|
|
138
|
+
outline.kind === "document" ? markDocumentSections(shown, outline.headings) : shown
|
|
127
139
|
return new Response(
|
|
128
140
|
injectFrameAssets(
|
|
129
141
|
rewriteFrameReferences(source, frame.targets, file.path),
|
|
130
142
|
layout,
|
|
131
|
-
file.path
|
|
143
|
+
file.path,
|
|
144
|
+
outline.kind === "document" ? outline.paper : undefined
|
|
132
145
|
),
|
|
133
146
|
{ headers }
|
|
134
147
|
)
|