@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/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// src/server.ts
|
|
3
3
|
import { cors } from "@elysiajs/cors";
|
|
4
4
|
import { openapi } from "@elysiajs/openapi";
|
|
5
|
+
import { ACTION_RUN_DRAIN_TIMEOUT_MS } from "@sixb/core/internal/actions";
|
|
5
6
|
import { bindAgentRunRequestExecution as bindAgentRunRequestExecution2 } from "@sixb/core/internal/agent-execution";
|
|
6
7
|
import { ARTIFACT_FRAME_ROUTE_PREFIX as ARTIFACT_FRAME_ROUTE_PREFIX4 } from "@sixb/core/internal/artifacts/frames";
|
|
7
8
|
import { CSRF_HEADER_NAME as CSRF_HEADER_NAME2, setRequestClientAddress } from "@sixb/core/internal/auth";
|
|
@@ -889,7 +890,8 @@ var PrincipalSchema = z.object({
|
|
|
889
890
|
type: z.enum(["user", "serviceAccount", "system"]),
|
|
890
891
|
id: z.string().min(1)
|
|
891
892
|
});
|
|
892
|
-
var
|
|
893
|
+
var jsonValueUnion;
|
|
894
|
+
var JsonValueSchema = z.lazy(() => jsonValueUnion ??= z.union([
|
|
893
895
|
z.string(),
|
|
894
896
|
z.number().finite(),
|
|
895
897
|
z.boolean(),
|
|
@@ -1148,7 +1150,7 @@ import {
|
|
|
1148
1150
|
import { z as z10 } from "zod";
|
|
1149
1151
|
|
|
1150
1152
|
// src/schemas/agents.ts
|
|
1151
|
-
import { MAX_AGENT_CONTEXT_ENTRIES } from "@sixb/core";
|
|
1153
|
+
import { AGENT_MESSAGE_DELIVERIES, MAX_AGENT_CONTEXT_ENTRIES } from "@sixb/core";
|
|
1152
1154
|
import { MAX_AGENT_CONTEXT_LABEL_LENGTH } from "@sixb/core/agents/context";
|
|
1153
1155
|
import { CONTROL_CHARACTER } from "@sixb/core/internal/agent-run-storage-provider";
|
|
1154
1156
|
import { LANGUAGE_MODEL_TIERS as LANGUAGE_MODEL_TIERS2 } from "@sixb/core/models";
|
|
@@ -1247,6 +1249,7 @@ var AgentPreferencesSchema = z4.object({
|
|
|
1247
1249
|
});
|
|
1248
1250
|
|
|
1249
1251
|
// src/schemas/ai-accounting.ts
|
|
1252
|
+
import { canonicalTimeZone } from "@sixb/core/calendar";
|
|
1250
1253
|
import { z as z8 } from "zod";
|
|
1251
1254
|
|
|
1252
1255
|
// src/schemas/ai-usage.ts
|
|
@@ -1544,8 +1547,15 @@ var InlineAudioSchema = z7.object({
|
|
|
1544
1547
|
var TranscriptionBodySchema = GenerationBodyBase.extend({
|
|
1545
1548
|
audio: z7.union([FileRefSchema, InlineAudioSchema])
|
|
1546
1549
|
});
|
|
1550
|
+
var TranscriptionWordSchema = z7.object({
|
|
1551
|
+
text: z7.string(),
|
|
1552
|
+
startMs: z7.number().int().nonnegative(),
|
|
1553
|
+
endMs: z7.number().int().nonnegative(),
|
|
1554
|
+
speaker: z7.string().optional()
|
|
1555
|
+
});
|
|
1547
1556
|
var TranscriptionSchema = GenerationResultBase.extend({
|
|
1548
|
-
text: z7.string()
|
|
1557
|
+
text: z7.string(),
|
|
1558
|
+
words: z7.array(TranscriptionWordSchema).optional()
|
|
1549
1559
|
});
|
|
1550
1560
|
|
|
1551
1561
|
// src/schemas/ai-accounting.ts
|
|
@@ -1578,8 +1588,12 @@ var AiAccountingRangeQuerySchema = z8.object({
|
|
|
1578
1588
|
source: z8.string().regex(/^(agent|action|other|workflow|workflow:.+)$/).optional().describe("Calls from agent conversations and their sub-agents, actions, workflows or one as workflow:<id>, or other"),
|
|
1579
1589
|
kind: ModelKindSchema.optional().describe("Calls to one kind of model")
|
|
1580
1590
|
});
|
|
1591
|
+
var TimeZoneSchema = z8.string().trim().min(1).refine((value) => canonicalTimeZone(value) !== undefined, {
|
|
1592
|
+
message: "Use an IANA time zone such as America/New_York"
|
|
1593
|
+
});
|
|
1581
1594
|
var AiAccountingOverviewQuerySchema = AiAccountingRangeQuerySchema.extend({
|
|
1582
|
-
bucket: AiAccountingBucketSchema
|
|
1595
|
+
bucket: AiAccountingBucketSchema,
|
|
1596
|
+
timeZone: TimeZoneSchema.optional().describe("The IANA time zone whose days, weeks or hours the periods follow, such as America/New_York; UTC when absent")
|
|
1583
1597
|
});
|
|
1584
1598
|
var AiModelCallAccountingListQuerySchema = AiAccountingRangeQuerySchema.extend({
|
|
1585
1599
|
executionId: z8.string().trim().min(1).optional(),
|
|
@@ -1851,6 +1865,7 @@ var AgentAuthorizablePrincipalSchema = z9.object({
|
|
|
1851
1865
|
type: z9.enum(["user", "serviceAccount"]),
|
|
1852
1866
|
id: z9.string().min(1)
|
|
1853
1867
|
});
|
|
1868
|
+
var AgentMessageDeliverySchema = z9.enum(AGENT_MESSAGE_DELIVERIES);
|
|
1854
1869
|
var AgentObjectContextSchema = z9.object({
|
|
1855
1870
|
kind: z9.literal("object"),
|
|
1856
1871
|
ref: z9.object({
|
|
@@ -1920,6 +1935,31 @@ var AgentThreadParticipantSchema = z9.object({
|
|
|
1920
1935
|
addedAt: z9.string(),
|
|
1921
1936
|
addedBy: AgentPrincipalSchema
|
|
1922
1937
|
});
|
|
1938
|
+
var AgentRunStatusSchema = z9.enum([
|
|
1939
|
+
"queued",
|
|
1940
|
+
"running",
|
|
1941
|
+
"succeeded",
|
|
1942
|
+
"failed",
|
|
1943
|
+
"cancelled"
|
|
1944
|
+
]);
|
|
1945
|
+
var AgentRunFinishReasonSchema = z9.enum(AGENT_RUN_FINISH_REASONS);
|
|
1946
|
+
var AgentThreadReadSchema = z9.object({
|
|
1947
|
+
threadId: z9.string(),
|
|
1948
|
+
throughSeq: z9.number(),
|
|
1949
|
+
headSeq: z9.number(),
|
|
1950
|
+
unread: z9.number(),
|
|
1951
|
+
readAt: z9.string().optional()
|
|
1952
|
+
});
|
|
1953
|
+
var AgentThreadLastRunSchema = z9.object({
|
|
1954
|
+
id: z9.string(),
|
|
1955
|
+
status: AgentRunStatusSchema,
|
|
1956
|
+
finishReason: AgentRunFinishReasonSchema.optional(),
|
|
1957
|
+
errorCode: z9.enum(AGENT_RUN_FAILURE_CODES).optional(),
|
|
1958
|
+
completedAt: z9.string().optional(),
|
|
1959
|
+
requestedBy: AgentAuthorizablePrincipalSchema.optional()
|
|
1960
|
+
});
|
|
1961
|
+
var MarkAgentThreadReadBodySchema = z9.object({ throughMessageId: z9.string().trim().min(1).optional() }).strict();
|
|
1962
|
+
var MarkAgentThreadReadResponseSchema = z9.object({ read: AgentThreadReadSchema });
|
|
1923
1963
|
var AgentThreadSchema = z9.object({
|
|
1924
1964
|
sandboxState: z9.object({
|
|
1925
1965
|
name: z9.string(),
|
|
@@ -1954,6 +1994,8 @@ var AgentThreadSchema = z9.object({
|
|
|
1954
1994
|
messageCount: z9.number(),
|
|
1955
1995
|
createdAt: z9.string(),
|
|
1956
1996
|
updatedAt: z9.string(),
|
|
1997
|
+
read: AgentThreadReadSchema.optional(),
|
|
1998
|
+
lastRun: AgentThreadLastRunSchema.optional(),
|
|
1957
1999
|
approvalMode: AgentApprovalModeSchema.optional(),
|
|
1958
2000
|
approvalModeSource: AgentApprovalModeSourceSchema.optional()
|
|
1959
2001
|
});
|
|
@@ -2130,6 +2172,17 @@ var AgentMessageListResponseSchema = z9.object({
|
|
|
2130
2172
|
hasMore: z9.boolean(),
|
|
2131
2173
|
total: z9.number()
|
|
2132
2174
|
});
|
|
2175
|
+
var EditAgentMessageBodySchema = z9.object({
|
|
2176
|
+
text: z9.string().trim().min(1).optional(),
|
|
2177
|
+
model: LanguageModelRefSchema.optional(),
|
|
2178
|
+
reasoning: ModelReasoningSchema.optional(),
|
|
2179
|
+
timeZone: z9.string().trim().min(1).max(100).optional(),
|
|
2180
|
+
locale: z9.string().trim().min(1).max(100).optional(),
|
|
2181
|
+
approvalMode: AgentApprovalModeSchema.optional(),
|
|
2182
|
+
attachments: z9.array(FileRefSchema).optional(),
|
|
2183
|
+
context: z9.array(AgentContextEntryInputSchema).max(MAX_AGENT_CONTEXT_ENTRIES).optional(),
|
|
2184
|
+
nextMessageId: z9.string().trim().min(1).optional()
|
|
2185
|
+
}).strict();
|
|
2133
2186
|
var PostAgentMessageBodySchema = z9.object({
|
|
2134
2187
|
text: z9.string().trim().min(1).optional(),
|
|
2135
2188
|
continue: z9.literal(true).optional(),
|
|
@@ -2140,7 +2193,8 @@ var PostAgentMessageBodySchema = z9.object({
|
|
|
2140
2193
|
approvalMode: AgentApprovalModeSchema.optional(),
|
|
2141
2194
|
attachments: z9.array(FileRefSchema).optional(),
|
|
2142
2195
|
context: z9.array(AgentContextEntryInputSchema).max(MAX_AGENT_CONTEXT_ENTRIES).optional(),
|
|
2143
|
-
messageId: z9.string().trim().min(1).optional()
|
|
2196
|
+
messageId: z9.string().trim().min(1).optional(),
|
|
2197
|
+
delivery: AgentMessageDeliverySchema.optional()
|
|
2144
2198
|
}).strict();
|
|
2145
2199
|
var AgentRequestErrorResponseSchema = ErrorResponseSchema.extend({
|
|
2146
2200
|
code: z9.string().optional()
|
|
@@ -2148,14 +2202,6 @@ var AgentRequestErrorResponseSchema = ErrorResponseSchema.extend({
|
|
|
2148
2202
|
var CancelAgentRunBodySchema = z9.object({
|
|
2149
2203
|
runId: z9.string().trim().min(1)
|
|
2150
2204
|
});
|
|
2151
|
-
var AgentRunStatusSchema = z9.enum([
|
|
2152
|
-
"queued",
|
|
2153
|
-
"running",
|
|
2154
|
-
"succeeded",
|
|
2155
|
-
"failed",
|
|
2156
|
-
"cancelled"
|
|
2157
|
-
]);
|
|
2158
|
-
var AgentRunFinishReasonSchema = z9.enum(AGENT_RUN_FINISH_REASONS);
|
|
2159
2205
|
var AgentRunSchema = z9.object({
|
|
2160
2206
|
id: z9.string(),
|
|
2161
2207
|
projectId: z9.string(),
|
|
@@ -2170,6 +2216,7 @@ var AgentRunSchema = z9.object({
|
|
|
2170
2216
|
reasoning: ModelReasoningSchema.optional(),
|
|
2171
2217
|
approvalMode: AgentApprovalModeSchema.optional(),
|
|
2172
2218
|
runsOn: z9.literal("computer").optional(),
|
|
2219
|
+
computer: z9.object({ id: z9.string(), folder: z9.string() }).optional(),
|
|
2173
2220
|
modelId: z9.string().optional(),
|
|
2174
2221
|
finishReason: AgentRunFinishReasonSchema.optional(),
|
|
2175
2222
|
usage: AiUsageSummarySchema.optional(),
|
|
@@ -2182,8 +2229,51 @@ var AgentRunSchema = z9.object({
|
|
|
2182
2229
|
startedAt: z9.string().optional(),
|
|
2183
2230
|
completedAt: z9.string().optional()
|
|
2184
2231
|
});
|
|
2232
|
+
var AgentInboxItemSchema = z9.object({
|
|
2233
|
+
id: z9.string(),
|
|
2234
|
+
projectId: z9.string(),
|
|
2235
|
+
threadId: z9.string(),
|
|
2236
|
+
messageId: z9.string(),
|
|
2237
|
+
seq: z9.number(),
|
|
2238
|
+
authorPrincipal: AgentPrincipalSchema,
|
|
2239
|
+
mode: z9.enum(["steer", "queue"]),
|
|
2240
|
+
parts: z9.array(AgentMessagePartSchema),
|
|
2241
|
+
spec: z9.object({
|
|
2242
|
+
model: LanguageModelRefSchema.optional(),
|
|
2243
|
+
reasoning: ModelReasoningSchema.optional(),
|
|
2244
|
+
approvalMode: AgentApprovalModeSchema.optional()
|
|
2245
|
+
}).optional(),
|
|
2246
|
+
timeZone: z9.string().optional(),
|
|
2247
|
+
locale: z9.string().optional(),
|
|
2248
|
+
immediate: z9.boolean().optional(),
|
|
2249
|
+
replacesMessageId: z9.string().optional(),
|
|
2250
|
+
createdAt: z9.string(),
|
|
2251
|
+
updatedAt: z9.string()
|
|
2252
|
+
});
|
|
2253
|
+
var AgentInboxListResponseSchema = z9.object({
|
|
2254
|
+
items: z9.array(AgentInboxItemSchema)
|
|
2255
|
+
});
|
|
2256
|
+
var AgentThreadInboxParamsSchema = AgentThreadParamsSchema.extend({
|
|
2257
|
+
itemId: z9.string().min(1)
|
|
2258
|
+
});
|
|
2259
|
+
var UpdateAgentInboxItemBodySchema = z9.object({
|
|
2260
|
+
text: z9.string().trim().min(1).optional(),
|
|
2261
|
+
model: LanguageModelRefSchema.optional(),
|
|
2262
|
+
reasoning: ModelReasoningSchema.optional(),
|
|
2263
|
+
approvalMode: AgentApprovalModeSchema.optional(),
|
|
2264
|
+
delivery: z9.enum(["steer", "queue"]).optional(),
|
|
2265
|
+
immediate: z9.literal(true).optional()
|
|
2266
|
+
}).strict();
|
|
2267
|
+
var UpdateAgentInboxItemResponseSchema = z9.object({
|
|
2268
|
+
item: AgentInboxItemSchema
|
|
2269
|
+
});
|
|
2185
2270
|
var PostAgentMessageResponseSchema = z9.object({
|
|
2186
|
-
run: AgentRunSchema
|
|
2271
|
+
run: AgentRunSchema.optional(),
|
|
2272
|
+
item: AgentInboxItemSchema.optional()
|
|
2273
|
+
});
|
|
2274
|
+
var EditAgentMessageResponseSchema = z9.object({
|
|
2275
|
+
run: AgentRunSchema.optional(),
|
|
2276
|
+
item: AgentInboxItemSchema.optional()
|
|
2187
2277
|
});
|
|
2188
2278
|
var CancelAgentRunResponseSchema = z9.object({
|
|
2189
2279
|
run: AgentRunSchema
|
|
@@ -4469,7 +4559,22 @@ async function serializeThreads(host, threads, viewer) {
|
|
|
4469
4559
|
lastMessageAt: thread.lastMessageAt ? toIsoString(thread.lastMessageAt) : undefined,
|
|
4470
4560
|
messageCount: thread.messageCount,
|
|
4471
4561
|
createdAt: toIsoString(thread.createdAt),
|
|
4472
|
-
updatedAt: toIsoString(thread.updatedAt)
|
|
4562
|
+
updatedAt: toIsoString(thread.updatedAt),
|
|
4563
|
+
read: thread.read && {
|
|
4564
|
+
threadId: thread.read.threadId,
|
|
4565
|
+
throughSeq: thread.read.throughSeq,
|
|
4566
|
+
headSeq: thread.read.headSeq,
|
|
4567
|
+
unread: thread.read.unread,
|
|
4568
|
+
readAt: thread.read.readAt ? toIsoString(thread.read.readAt) : undefined
|
|
4569
|
+
},
|
|
4570
|
+
lastRun: thread.lastRun && {
|
|
4571
|
+
id: thread.lastRun.id,
|
|
4572
|
+
status: thread.lastRun.status,
|
|
4573
|
+
finishReason: thread.lastRun.finishReason,
|
|
4574
|
+
errorCode: thread.lastRun.errorCode,
|
|
4575
|
+
completedAt: thread.lastRun.completedAt ? toIsoString(thread.lastRun.completedAt) : undefined,
|
|
4576
|
+
requestedBy: thread.lastRun.requestedBy
|
|
4577
|
+
}
|
|
4473
4578
|
}));
|
|
4474
4579
|
}
|
|
4475
4580
|
async function serializeThread(host, thread, viewer) {
|
|
@@ -4504,7 +4609,7 @@ function sameBackgroundCommand(command, ref) {
|
|
|
4504
4609
|
return command.threadId === ref.threadId && command.id === ref.id && command.startedAt === ref.startedAt;
|
|
4505
4610
|
}
|
|
4506
4611
|
function serializeMessage(message, annotations = [], checkpoint) {
|
|
4507
|
-
return
|
|
4612
|
+
return {
|
|
4508
4613
|
id: message.id,
|
|
4509
4614
|
projectId: message.projectId,
|
|
4510
4615
|
threadId: message.threadId,
|
|
@@ -4512,7 +4617,7 @@ function serializeMessage(message, annotations = [], checkpoint) {
|
|
|
4512
4617
|
role: message.role,
|
|
4513
4618
|
authorPrincipal: message.authorPrincipal,
|
|
4514
4619
|
seq: message.seq,
|
|
4515
|
-
parts: message.parts,
|
|
4620
|
+
parts: message.parts.map(withoutReplayState),
|
|
4516
4621
|
annotations,
|
|
4517
4622
|
compaction: checkpoint ? {
|
|
4518
4623
|
checkpointId: checkpoint.id,
|
|
@@ -4524,9 +4629,36 @@ function serializeMessage(message, annotations = [], checkpoint) {
|
|
|
4524
4629
|
contentVersion: message.contentVersion,
|
|
4525
4630
|
createdAt: toIsoString(message.createdAt),
|
|
4526
4631
|
completedAt: message.completedAt ? toIsoString(message.completedAt) : undefined
|
|
4632
|
+
};
|
|
4633
|
+
}
|
|
4634
|
+
function withoutReplayState(part) {
|
|
4635
|
+
if (part.type === "provider-state")
|
|
4636
|
+
return { ...part, data: null };
|
|
4637
|
+
if (!("providerMetadata" in part) || part.providerMetadata === undefined)
|
|
4638
|
+
return part;
|
|
4639
|
+
const { providerMetadata: _replay, ...shown } = part;
|
|
4640
|
+
return shown;
|
|
4641
|
+
}
|
|
4642
|
+
function serializeAgentInboxItem(item) {
|
|
4643
|
+
return AgentInboxItemSchema.parse({
|
|
4644
|
+
id: item.id,
|
|
4645
|
+
projectId: item.projectId,
|
|
4646
|
+
threadId: item.threadId,
|
|
4647
|
+
messageId: item.messageId,
|
|
4648
|
+
seq: item.seq,
|
|
4649
|
+
authorPrincipal: item.authorPrincipal,
|
|
4650
|
+
mode: item.mode,
|
|
4651
|
+
parts: item.parts,
|
|
4652
|
+
spec: item.spec,
|
|
4653
|
+
timeZone: item.timeZone,
|
|
4654
|
+
locale: item.locale,
|
|
4655
|
+
immediate: item.immediate === true ? true : undefined,
|
|
4656
|
+
replacesMessageId: item.replacesMessageId,
|
|
4657
|
+
createdAt: toIsoString(item.createdAt),
|
|
4658
|
+
updatedAt: toIsoString(item.updatedAt)
|
|
4527
4659
|
});
|
|
4528
4660
|
}
|
|
4529
|
-
function serializeAgentRun(run) {
|
|
4661
|
+
function serializeAgentRun(run, { ownerReads = false } = {}) {
|
|
4530
4662
|
return AgentRunSchema.parse({
|
|
4531
4663
|
id: run.id,
|
|
4532
4664
|
projectId: run.projectId,
|
|
@@ -4541,6 +4673,7 @@ function serializeAgentRun(run) {
|
|
|
4541
4673
|
reasoning: run.spec?.reasoning,
|
|
4542
4674
|
approvalMode: run.spec?.approvalMode,
|
|
4543
4675
|
runsOn: run.kind === "conversation" ? run.spec?.runsOn : undefined,
|
|
4676
|
+
computer: ownerReads && run.kind === "conversation" ? run.spec?.computer : undefined,
|
|
4544
4677
|
modelId: run.modelId,
|
|
4545
4678
|
finishReason: run.finishReason,
|
|
4546
4679
|
usage: run.usage,
|
|
@@ -4567,6 +4700,17 @@ async function getAgentMessageFileContentThread(params) {
|
|
|
4567
4700
|
}
|
|
4568
4701
|
return params.authState.sixb.agent.threads.getById(params.threadId);
|
|
4569
4702
|
}
|
|
4703
|
+
function handleAgentInboxRouteError(error, set) {
|
|
4704
|
+
if (error instanceof AgentStorageError2 && error.code === "invalid_state") {
|
|
4705
|
+
set.status = 409;
|
|
4706
|
+
return { error: "A turn already read this message", code: error.code };
|
|
4707
|
+
}
|
|
4708
|
+
if (error instanceof AgentStorageError2 && error.code === "inbox_limit") {
|
|
4709
|
+
set.status = 409;
|
|
4710
|
+
return { error: "Too many messages are waiting in this conversation", code: error.code };
|
|
4711
|
+
}
|
|
4712
|
+
return handleAgentRouteError(error, set);
|
|
4713
|
+
}
|
|
4570
4714
|
function handleAgentRouteError(error, set) {
|
|
4571
4715
|
if (error instanceof AgentStorageError2 && error.code === "duplicate_id") {
|
|
4572
4716
|
set.status = 409;
|
|
@@ -4583,12 +4727,14 @@ function handleAgentRouteError(error, set) {
|
|
|
4583
4727
|
if (error instanceof AgentRequestError) {
|
|
4584
4728
|
switch (error.code) {
|
|
4585
4729
|
case "agent_not_found":
|
|
4730
|
+
case "message_not_found":
|
|
4586
4731
|
case "run_not_found":
|
|
4587
4732
|
case "thread_not_found":
|
|
4588
4733
|
case "approval_not_found":
|
|
4589
4734
|
set.status = 404;
|
|
4590
4735
|
break;
|
|
4591
4736
|
case "active_run_exists":
|
|
4737
|
+
case "message_not_editable":
|
|
4592
4738
|
case "thread_not_conversation":
|
|
4593
4739
|
case "run_not_retryable":
|
|
4594
4740
|
case "run_not_active":
|
|
@@ -4598,6 +4744,7 @@ function handleAgentRouteError(error, set) {
|
|
|
4598
4744
|
set.status = 409;
|
|
4599
4745
|
break;
|
|
4600
4746
|
case "authority_not_inheritable":
|
|
4747
|
+
case "not_message_author":
|
|
4601
4748
|
case "not_thread_owner":
|
|
4602
4749
|
case "not_run_requester":
|
|
4603
4750
|
set.status = 403;
|
|
@@ -4965,6 +5112,34 @@ function registerAgentRoutes(app, host) {
|
|
|
4965
5112
|
tags: [OPENAPI_TAGS.agentThreads.name],
|
|
4966
5113
|
security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT
|
|
4967
5114
|
}
|
|
5115
|
+
}).post("/api/agent-threads/:threadId/sandbox/restore", async (context) => {
|
|
5116
|
+
try {
|
|
5117
|
+
const sixb = requireRequestSixb(context);
|
|
5118
|
+
const thread = await sixb.agent.threads.restoreSandbox(context.params.threadId, context.body);
|
|
5119
|
+
return serializeThread(host, thread, requestActor(sixb));
|
|
5120
|
+
} catch (error) {
|
|
5121
|
+
if (error instanceof AgentStorageError2 && error.code === "invalid_state") {
|
|
5122
|
+
context.set.status = 409;
|
|
5123
|
+
return { error: "Sandbox state changed or a run is active. Reload and try again." };
|
|
5124
|
+
}
|
|
5125
|
+
return handleAgentRouteError(error, context.set);
|
|
5126
|
+
}
|
|
5127
|
+
}, {
|
|
5128
|
+
params: AgentThreadParamsSchema,
|
|
5129
|
+
body: z13.object({ expectedSandboxName: z13.string().min(1) }).strict(),
|
|
5130
|
+
response: {
|
|
5131
|
+
200: AgentThreadSchema,
|
|
5132
|
+
400: ErrorResponseSchema,
|
|
5133
|
+
403: AgentRequestErrorResponseSchema,
|
|
5134
|
+
404: ErrorResponseSchema,
|
|
5135
|
+
409: AgentRequestErrorResponseSchema
|
|
5136
|
+
},
|
|
5137
|
+
detail: {
|
|
5138
|
+
summary: "Explicitly go on in the workspace a failed save left, with its files as they were",
|
|
5139
|
+
operationId: "restoreAgentThreadSandbox",
|
|
5140
|
+
tags: [OPENAPI_TAGS.agentThreads.name],
|
|
5141
|
+
security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT
|
|
5142
|
+
}
|
|
4968
5143
|
}).get("/api/agent-threads/:threadId/messages", async (context) => {
|
|
4969
5144
|
const { params, query, set } = context;
|
|
4970
5145
|
const authState = requestAuthState(context);
|
|
@@ -4984,7 +5159,7 @@ function registerAgentRoutes(app, host) {
|
|
|
4984
5159
|
return { error: "Agent thread not found" };
|
|
4985
5160
|
}
|
|
4986
5161
|
const parsed = AgentMessagesQuerySchema.parse(query);
|
|
4987
|
-
return
|
|
5162
|
+
return await readThreadMessages(host, storage, thread, parsed);
|
|
4988
5163
|
} catch (error) {
|
|
4989
5164
|
return handleAgentRouteError(error, set);
|
|
4990
5165
|
}
|
|
@@ -5050,13 +5225,14 @@ function registerAgentRoutes(app, host) {
|
|
|
5050
5225
|
context: parsed.context,
|
|
5051
5226
|
messageId: parsed.messageId
|
|
5052
5227
|
};
|
|
5053
|
-
const
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
run: serializeAgentRun(result.run)
|
|
5228
|
+
const sent = await sixb.agent.runs.send({
|
|
5229
|
+
...requestInput,
|
|
5230
|
+
delivery: parsed.delivery
|
|
5057
5231
|
});
|
|
5232
|
+
set.status = 202;
|
|
5233
|
+
return PostAgentMessageResponseSchema.parse(sent.kind === "turn" ? { run: serializeAgentRun(sent.run) } : { item: serializeAgentInboxItem(sent.item) });
|
|
5058
5234
|
} catch (error) {
|
|
5059
|
-
return
|
|
5235
|
+
return handleAgentInboxRouteError(error, set);
|
|
5060
5236
|
}
|
|
5061
5237
|
}, {
|
|
5062
5238
|
params: AgentThreadParamsSchema,
|
|
@@ -5076,6 +5252,141 @@ function registerAgentRoutes(app, host) {
|
|
|
5076
5252
|
operationId: "postAgentThreadMessage",
|
|
5077
5253
|
security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT
|
|
5078
5254
|
}
|
|
5255
|
+
}).get("/api/agent-threads/:threadId/inbox", async (context) => {
|
|
5256
|
+
const { params, set } = context;
|
|
5257
|
+
const sixb = requireRequestSixb(context);
|
|
5258
|
+
try {
|
|
5259
|
+
if (!host.storage.agents) {
|
|
5260
|
+
return missingAgentStorageResponse(set);
|
|
5261
|
+
}
|
|
5262
|
+
const items = await sixb.agent.inbox.list(params.threadId);
|
|
5263
|
+
return AgentInboxListResponseSchema.parse({
|
|
5264
|
+
items: items.map(serializeAgentInboxItem)
|
|
5265
|
+
});
|
|
5266
|
+
} catch (error) {
|
|
5267
|
+
return handleAgentRouteError(error, set);
|
|
5268
|
+
}
|
|
5269
|
+
}, {
|
|
5270
|
+
params: AgentThreadParamsSchema,
|
|
5271
|
+
response: {
|
|
5272
|
+
200: AgentInboxListResponseSchema,
|
|
5273
|
+
400: AgentRequestErrorResponseSchema,
|
|
5274
|
+
404: ErrorResponseSchema,
|
|
5275
|
+
501: ErrorResponseSchema
|
|
5276
|
+
},
|
|
5277
|
+
detail: {
|
|
5278
|
+
summary: "List agent thread inbox messages",
|
|
5279
|
+
tags: [OPENAPI_TAGS.agentThreads.name],
|
|
5280
|
+
operationId: "listAgentThreadInbox",
|
|
5281
|
+
security: accessTokenSecurityRequirement("listAgentThreadInbox")
|
|
5282
|
+
}
|
|
5283
|
+
}).patch("/api/agent-threads/:threadId/inbox/:itemId", async (context) => {
|
|
5284
|
+
const { params, body, set } = context;
|
|
5285
|
+
const sixb = requireRequestSixb(context);
|
|
5286
|
+
try {
|
|
5287
|
+
if (!host.storage.agents) {
|
|
5288
|
+
return missingAgentStorageResponse(set);
|
|
5289
|
+
}
|
|
5290
|
+
const parsed = UpdateAgentInboxItemBodySchema.parse(body);
|
|
5291
|
+
const item = await sixb.agent.inbox.update(params.threadId, params.itemId, parsed);
|
|
5292
|
+
return UpdateAgentInboxItemResponseSchema.parse({
|
|
5293
|
+
item: serializeAgentInboxItem(item)
|
|
5294
|
+
});
|
|
5295
|
+
} catch (error) {
|
|
5296
|
+
return handleAgentInboxRouteError(error, set);
|
|
5297
|
+
}
|
|
5298
|
+
}, {
|
|
5299
|
+
params: AgentThreadInboxParamsSchema,
|
|
5300
|
+
body: UpdateAgentInboxItemBodySchema,
|
|
5301
|
+
response: {
|
|
5302
|
+
200: UpdateAgentInboxItemResponseSchema,
|
|
5303
|
+
400: AgentRequestErrorResponseSchema,
|
|
5304
|
+
403: AgentRequestErrorResponseSchema,
|
|
5305
|
+
404: ErrorResponseSchema,
|
|
5306
|
+
409: AgentRequestErrorResponseSchema,
|
|
5307
|
+
501: ErrorResponseSchema
|
|
5308
|
+
},
|
|
5309
|
+
detail: {
|
|
5310
|
+
summary: "Update a waiting agent thread message",
|
|
5311
|
+
tags: [OPENAPI_TAGS.agentThreads.name],
|
|
5312
|
+
operationId: "updateAgentThreadInboxItem",
|
|
5313
|
+
security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT
|
|
5314
|
+
}
|
|
5315
|
+
}).delete("/api/agent-threads/:threadId/inbox/:itemId", async (context) => {
|
|
5316
|
+
const { params, set } = context;
|
|
5317
|
+
const sixb = requireRequestSixb(context);
|
|
5318
|
+
try {
|
|
5319
|
+
if (!host.storage.agents) {
|
|
5320
|
+
return missingAgentStorageResponse(set);
|
|
5321
|
+
}
|
|
5322
|
+
await sixb.agent.inbox.remove(params.threadId, params.itemId);
|
|
5323
|
+
set.status = 204;
|
|
5324
|
+
return;
|
|
5325
|
+
} catch (error) {
|
|
5326
|
+
return handleAgentInboxRouteError(error, set);
|
|
5327
|
+
}
|
|
5328
|
+
}, {
|
|
5329
|
+
params: AgentThreadInboxParamsSchema,
|
|
5330
|
+
response: {
|
|
5331
|
+
204: z13.void(),
|
|
5332
|
+
400: AgentRequestErrorResponseSchema,
|
|
5333
|
+
403: AgentRequestErrorResponseSchema,
|
|
5334
|
+
404: ErrorResponseSchema,
|
|
5335
|
+
409: AgentRequestErrorResponseSchema,
|
|
5336
|
+
501: ErrorResponseSchema
|
|
5337
|
+
},
|
|
5338
|
+
detail: {
|
|
5339
|
+
summary: "Withdraw a waiting agent thread message",
|
|
5340
|
+
tags: [OPENAPI_TAGS.agentThreads.name],
|
|
5341
|
+
operationId: "withdrawAgentThreadInboxItem",
|
|
5342
|
+
security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT
|
|
5343
|
+
}
|
|
5344
|
+
}).post("/api/agent-threads/:threadId/messages/:messageId/edit", async (context) => {
|
|
5345
|
+
const { params, body, set } = context;
|
|
5346
|
+
const sixb = requireRequestSixb(context);
|
|
5347
|
+
try {
|
|
5348
|
+
const storage = host.storage.agents;
|
|
5349
|
+
if (!storage) {
|
|
5350
|
+
return missingAgentStorageResponse(set);
|
|
5351
|
+
}
|
|
5352
|
+
const parsed = EditAgentMessageBodySchema.parse(body);
|
|
5353
|
+
const result = await sixb.agent.runs.editMessage({
|
|
5354
|
+
threadId: params.threadId,
|
|
5355
|
+
messageId: params.messageId,
|
|
5356
|
+
text: parsed.text,
|
|
5357
|
+
model: parsed.model,
|
|
5358
|
+
reasoning: parsed.reasoning,
|
|
5359
|
+
timeZone: parsed.timeZone,
|
|
5360
|
+
locale: parsed.locale,
|
|
5361
|
+
approvalMode: parsed.approvalMode,
|
|
5362
|
+
attachments: parsed.attachments,
|
|
5363
|
+
context: parsed.context,
|
|
5364
|
+
nextMessageId: parsed.nextMessageId
|
|
5365
|
+
});
|
|
5366
|
+
set.status = 202;
|
|
5367
|
+
return EditAgentMessageResponseSchema.parse(result.kind === "turn" ? { run: serializeAgentRun(result.run) } : { item: serializeAgentInboxItem(result.item) });
|
|
5368
|
+
} catch (error) {
|
|
5369
|
+
return handleAgentInboxRouteError(error, set);
|
|
5370
|
+
}
|
|
5371
|
+
}, {
|
|
5372
|
+
params: AgentMessageFileContentParamsSchema,
|
|
5373
|
+
body: EditAgentMessageBodySchema,
|
|
5374
|
+
response: {
|
|
5375
|
+
202: EditAgentMessageResponseSchema,
|
|
5376
|
+
400: AgentRequestErrorResponseSchema,
|
|
5377
|
+
403: AgentRequestErrorResponseSchema,
|
|
5378
|
+
404: ErrorResponseSchema,
|
|
5379
|
+
409: AgentRequestErrorResponseSchema,
|
|
5380
|
+
429: AiUsageLimitErrorResponseSchema,
|
|
5381
|
+
501: ErrorResponseSchema
|
|
5382
|
+
},
|
|
5383
|
+
detail: {
|
|
5384
|
+
summary: "Edit an agent thread message and restart from that turn",
|
|
5385
|
+
description: "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.",
|
|
5386
|
+
tags: [OPENAPI_TAGS.agentThreads.name],
|
|
5387
|
+
operationId: "editAgentThreadMessage",
|
|
5388
|
+
security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT
|
|
5389
|
+
}
|
|
5079
5390
|
}).post("/api/agent-threads/:threadId/cancel", async (context) => {
|
|
5080
5391
|
const { params, body, set } = context;
|
|
5081
5392
|
const sixb = requireRequestSixb(context);
|
|
@@ -5244,18 +5555,22 @@ function registerAgentRoutes(app, host) {
|
|
|
5244
5555
|
return missingAgentStorageResponse(set);
|
|
5245
5556
|
}
|
|
5246
5557
|
const parsed = AgentRunListQuerySchema.parse(query);
|
|
5247
|
-
const result = await
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
|
|
5558
|
+
const [result, thread] = await Promise.all([
|
|
5559
|
+
sixb.agent.runs.listForThread(params.threadId, {
|
|
5560
|
+
statuses: parsed.status ? [parsed.status] : undefined,
|
|
5561
|
+
limit: parseOptionalInt(parsed.limit),
|
|
5562
|
+
offset: parseOptionalInt(parsed.offset),
|
|
5563
|
+
order: parsed.order
|
|
5564
|
+
}),
|
|
5565
|
+
storage.threads.getById({ projectId: host.id, id: params.threadId })
|
|
5566
|
+
]);
|
|
5253
5567
|
if (!result) {
|
|
5254
5568
|
set.status = 404;
|
|
5255
5569
|
return { error: "Agent thread not found" };
|
|
5256
5570
|
}
|
|
5571
|
+
const ownerReads = thread !== null && principalsEqual(thread.ownerPrincipal, requestActor(sixb));
|
|
5257
5572
|
return AgentRunListResponseSchema.parse({
|
|
5258
|
-
runs: result.runs.map(serializeAgentRun),
|
|
5573
|
+
runs: result.runs.map((run) => serializeAgentRun(run, { ownerReads })),
|
|
5259
5574
|
hasMore: result.hasMore,
|
|
5260
5575
|
total: result.total
|
|
5261
5576
|
});
|
|
@@ -5793,7 +6108,7 @@ function registerAgentComputerRoutes(app, host) {
|
|
|
5793
6108
|
},
|
|
5794
6109
|
detail: {
|
|
5795
6110
|
summary: "Move a thread to one of your computers, in a folder there",
|
|
5796
|
-
description: "
|
|
6111
|
+
description: "Its turns run there alone from now on, in that folder: only `sixb` open in it claims them. Its owner moves it from the cloud or from another folder or computer, as often as they need; files from where it ran before stay there. Refused while a turn runs or waits on approvals.",
|
|
5797
6112
|
tags: [OPENAPI_TAGS.agentThreads.name],
|
|
5798
6113
|
operationId: "moveAgentThreadToComputer",
|
|
5799
6114
|
security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT
|
|
@@ -5821,7 +6136,7 @@ function registerAgentComputerRoutes(app, host) {
|
|
|
5821
6136
|
},
|
|
5822
6137
|
detail: {
|
|
5823
6138
|
summary: "Move a thread from your computer to the cloud",
|
|
5824
|
-
description: "Its turns run in the cloud from now on, starting with the one waiting for the computer, if any. The files it worked on stay on the computer. Refused while a turn runs there or waits on approvals.",
|
|
6139
|
+
description: "Its turns run in the cloud from now on, starting with the one waiting for the computer, if any, and its owner can move it to a computer or folder again later. The files it worked on stay on the computer. Refused while a turn runs there or waits on approvals.",
|
|
5825
6140
|
tags: [OPENAPI_TAGS.agentThreads.name],
|
|
5826
6141
|
operationId: "moveAgentThreadToCloud",
|
|
5827
6142
|
security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT
|
|
@@ -6325,10 +6640,13 @@ function startLapsedRunSweeper(host) {
|
|
|
6325
6640
|
}
|
|
6326
6641
|
function agentRunSessionHandler(host) {
|
|
6327
6642
|
let sessions;
|
|
6328
|
-
return async (request) => {
|
|
6643
|
+
return async (request, server) => {
|
|
6329
6644
|
sessions ??= agentRunSessionHost(host);
|
|
6330
6645
|
const served = sessions ? await serveAgentRunSession(sessions, request, {
|
|
6331
|
-
admitted: () =>
|
|
6646
|
+
admitted: () => {
|
|
6647
|
+
liftRequestBodyCap(request);
|
|
6648
|
+
server?.timeout(request, 0);
|
|
6649
|
+
}
|
|
6332
6650
|
}) : null;
|
|
6333
6651
|
if (served)
|
|
6334
6652
|
return served;
|
|
@@ -6400,6 +6718,48 @@ function answer(body, status = 200) {
|
|
|
6400
6718
|
});
|
|
6401
6719
|
}
|
|
6402
6720
|
|
|
6721
|
+
// src/routes/agent-thread-reads.ts
|
|
6722
|
+
var MARKING = "Record that your reading of a conversation reached a message, or its newest when `throughMessageId` is omitted, which is what a Done button sends. It never moves backwards, so another device that read further keeps its place; a message a retry or an edit took away marks nothing. Session routes only: a runner has no reading.";
|
|
6723
|
+
function registerAgentThreadReadRoutes(app, host) {
|
|
6724
|
+
return app.put("/api/agent-threads/:threadId/read", async (context) => {
|
|
6725
|
+
const { set } = context;
|
|
6726
|
+
try {
|
|
6727
|
+
if (!host.storage.agents) {
|
|
6728
|
+
return unconfiguredStorageResponse(set, "Agent storage");
|
|
6729
|
+
}
|
|
6730
|
+
const body = MarkAgentThreadReadBodySchema.parse(context.body ?? {});
|
|
6731
|
+
const read = await requireRequestSixb(context).agent.threads.markRead(context.params.threadId, body);
|
|
6732
|
+
return MarkAgentThreadReadResponseSchema.parse({
|
|
6733
|
+
read: {
|
|
6734
|
+
threadId: read.threadId,
|
|
6735
|
+
throughSeq: read.throughSeq,
|
|
6736
|
+
headSeq: read.headSeq,
|
|
6737
|
+
unread: read.unread,
|
|
6738
|
+
readAt: read.readAt ? toIsoString(read.readAt) : undefined
|
|
6739
|
+
}
|
|
6740
|
+
});
|
|
6741
|
+
} catch (error) {
|
|
6742
|
+
return handleAgentRouteError(error, set);
|
|
6743
|
+
}
|
|
6744
|
+
}, {
|
|
6745
|
+
params: AgentThreadParamsSchema,
|
|
6746
|
+
body: MarkAgentThreadReadBodySchema,
|
|
6747
|
+
response: {
|
|
6748
|
+
200: MarkAgentThreadReadResponseSchema,
|
|
6749
|
+
400: AgentRequestErrorResponseSchema,
|
|
6750
|
+
404: AgentRequestErrorResponseSchema,
|
|
6751
|
+
501: ErrorResponseSchema
|
|
6752
|
+
},
|
|
6753
|
+
detail: {
|
|
6754
|
+
summary: "Mark how far you have read an Agent thread",
|
|
6755
|
+
description: MARKING,
|
|
6756
|
+
tags: [OPENAPI_TAGS.agentThreads.name],
|
|
6757
|
+
operationId: "markAgentThreadRead",
|
|
6758
|
+
security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT
|
|
6759
|
+
}
|
|
6760
|
+
});
|
|
6761
|
+
}
|
|
6762
|
+
|
|
6403
6763
|
// src/routes/ai-accounting.ts
|
|
6404
6764
|
import { AiLimitStorageError } from "@sixb/core/storage";
|
|
6405
6765
|
|
|
@@ -6720,6 +7080,7 @@ function registerAiAccountingRoutes(app, host) {
|
|
|
6720
7080
|
from: new Date(parsed.from),
|
|
6721
7081
|
to: new Date(parsed.to),
|
|
6722
7082
|
bucket: parsed.bucket,
|
|
7083
|
+
...parsed.timeZone === undefined ? {} : { timeZone: parsed.timeZone },
|
|
6723
7084
|
providerId: parsed.providerId,
|
|
6724
7085
|
modelId: parsed.modelId,
|
|
6725
7086
|
...accountingFilters(parsed)
|
|
@@ -7025,7 +7386,9 @@ import {
|
|
|
7025
7386
|
FRAME_REFERENCE_PREFIX,
|
|
7026
7387
|
frameEntries,
|
|
7027
7388
|
frameLayout,
|
|
7389
|
+
frozenDocumentHtml,
|
|
7028
7390
|
injectFrameAssets,
|
|
7391
|
+
markDocumentSections,
|
|
7029
7392
|
resolveArtifactFrame,
|
|
7030
7393
|
rewriteFrameReferences
|
|
7031
7394
|
} from "@sixb/core/internal/artifacts/frames";
|
|
@@ -7108,7 +7471,7 @@ async function frameResponse(host, policy, { params, request }, options = {}) {
|
|
|
7108
7471
|
const file = version.files.find((candidate) => candidate.path === path);
|
|
7109
7472
|
if (!file)
|
|
7110
7473
|
return notFound();
|
|
7111
|
-
const layout = frameLayout(version
|
|
7474
|
+
const layout = frameLayout(version);
|
|
7112
7475
|
if (!lent && layout && frameEntries(version).includes(file.path)) {
|
|
7113
7476
|
const opened = await openFileRef(host.blobStorage, file.file);
|
|
7114
7477
|
if (!opened)
|
|
@@ -7118,9 +7481,12 @@ async function frameResponse(host, policy, { params, request }, options = {}) {
|
|
|
7118
7481
|
if (options.head)
|
|
7119
7482
|
return new Response(null, { headers });
|
|
7120
7483
|
const text = await new Response(opened.body).text();
|
|
7121
|
-
const
|
|
7122
|
-
const
|
|
7123
|
-
|
|
7484
|
+
const { outline } = version;
|
|
7485
|
+
const editing = (outline.kind === "canvas" || outline.kind === "document") && new URL(request.url).searchParams.has("sixb-edit");
|
|
7486
|
+
const marked = editing ? annotateBoard(text) : text;
|
|
7487
|
+
const shown = outline.kind === "document" && version.frozenAt ? frozenDocumentHtml(marked) : marked;
|
|
7488
|
+
const source = outline.kind === "document" ? markDocumentSections(shown, outline.headings) : shown;
|
|
7489
|
+
return new Response(injectFrameAssets(rewriteFrameReferences(source, frame.targets, file.path), layout, file.path, outline.kind === "document" ? outline.paper : undefined), { headers });
|
|
7124
7490
|
}
|
|
7125
7491
|
const response = await createFileContentResponse({
|
|
7126
7492
|
blobStorage: host.blobStorage,
|
|
@@ -7168,7 +7534,8 @@ import {
|
|
|
7168
7534
|
boardPreview,
|
|
7169
7535
|
boardPreviewStatuses,
|
|
7170
7536
|
boardPreviews,
|
|
7171
|
-
boardsReadLiveData
|
|
7537
|
+
boardsReadLiveData,
|
|
7538
|
+
documentPdfKey
|
|
7172
7539
|
} from "@sixb/core/internal/artifacts/publish";
|
|
7173
7540
|
import { ZodError as ZodError6 } from "zod";
|
|
7174
7541
|
|
|
@@ -7271,7 +7638,22 @@ var ArtifactFileSchema = z18.object({
|
|
|
7271
7638
|
});
|
|
7272
7639
|
var DocumentOutlineSchema = z18.object({
|
|
7273
7640
|
kind: z18.literal("document"),
|
|
7274
|
-
headings: z18.array(z18.object({ depth: z18.number().int(), text: z18.string(), slug: z18.string() }))
|
|
7641
|
+
headings: z18.array(z18.object({ depth: z18.number().int(), text: z18.string(), slug: z18.string() })),
|
|
7642
|
+
format: z18.literal("html").optional().describe("html for a designed document, document.html with its own stylesheets"),
|
|
7643
|
+
paper: z18.object({
|
|
7644
|
+
width: z18.number(),
|
|
7645
|
+
height: z18.number(),
|
|
7646
|
+
margin: z18.object({
|
|
7647
|
+
top: z18.number(),
|
|
7648
|
+
right: z18.number(),
|
|
7649
|
+
bottom: z18.number(),
|
|
7650
|
+
left: z18.number()
|
|
7651
|
+
})
|
|
7652
|
+
}).optional().describe("The sheet a designed document's @page rule sets, in CSS pixels: its size and margins"),
|
|
7653
|
+
holder: z18.object({
|
|
7654
|
+
objectTypeId: z18.string(),
|
|
7655
|
+
links: z18.array(z18.string()).describe("The holder's links its fields read through")
|
|
7656
|
+
}).optional().describe('The object a designed document shows live data of, as <meta name="sixb:object-type"> names its type: the one object of that type that holds the document')
|
|
7275
7657
|
});
|
|
7276
7658
|
var SheetOutlineSchema = z18.object({
|
|
7277
7659
|
kind: z18.literal("sheet"),
|
|
@@ -7354,8 +7736,28 @@ var ArtifactVersionSchema = z18.object({
|
|
|
7354
7736
|
updatedAt: z18.string().describe("When its content was last written"),
|
|
7355
7737
|
frozenAt: z18.string().optional().describe("When it was created, which froze it"),
|
|
7356
7738
|
frozenBy: PrincipalSchema.optional().describe("Who created it"),
|
|
7357
|
-
boardPreviews: z18.record(z18.string(), z18.enum(["ready", "pending", "none"])).optional().describe("A canvas's boards by id, as reading or publishing the version returns them: ready when its preview is, pending while it is rendered, none when none will come and the board shows its outline")
|
|
7739
|
+
boardPreviews: z18.record(z18.string(), z18.enum(["ready", "pending", "none"])).optional().describe("A canvas's boards by id, as reading or publishing the version returns them: ready when its preview is, pending while it is rendered, none when none will come and the board shows its outline"),
|
|
7740
|
+
printable: z18.boolean().optional().describe("true for a designed document in a project that prints to PDF: POST to its pdf route to print it, with the values whoever asks reads")
|
|
7741
|
+
});
|
|
7742
|
+
var ArtifactPdfKeySchema = z18.string().regex(/^sha256:[0-9a-f]{64}$/).describe("The values a document that shows live data prints: ask with it again, and get that PDF with it, whatever the values are by then");
|
|
7743
|
+
var ArtifactPdfResponseSchema = z18.discriminatedUnion("status", [
|
|
7744
|
+
z18.object({
|
|
7745
|
+
status: z18.literal("ready"),
|
|
7746
|
+
pages: z18.number().int().min(1).describe("How many pages it printed on"),
|
|
7747
|
+
key: ArtifactPdfKeySchema.optional()
|
|
7748
|
+
}),
|
|
7749
|
+
z18.object({ status: z18.literal("printing"), key: ArtifactPdfKeySchema.optional() }),
|
|
7750
|
+
z18.object({
|
|
7751
|
+
status: z18.literal("failed"),
|
|
7752
|
+
reason: z18.string().describe("Why it could not be printed"),
|
|
7753
|
+
key: ArtifactPdfKeySchema.optional()
|
|
7754
|
+
})
|
|
7755
|
+
]);
|
|
7756
|
+
var ArtifactPdfQuerySchema = z18.object({
|
|
7757
|
+
retry: z18.enum(["true", "false"]).optional().describe("true asks again for a PDF that could not be printed, instead of hearing why"),
|
|
7758
|
+
key: ArtifactPdfKeySchema.optional()
|
|
7358
7759
|
});
|
|
7760
|
+
var ArtifactPdfDownloadQuerySchema = z18.object({ key: ArtifactPdfKeySchema.optional() });
|
|
7359
7761
|
var ArtifactVersionSummarySchema = ArtifactVersionSchema.pick({
|
|
7360
7762
|
version: true,
|
|
7361
7763
|
revision: true,
|
|
@@ -7480,7 +7882,7 @@ var ArtifactFrameResponseSchema = z18.object({
|
|
|
7480
7882
|
expiresAt: z18.string().describe("When the frame stops serving; ask for a new one before then")
|
|
7481
7883
|
});
|
|
7482
7884
|
var ArtifactErrorResponseSchema = ErrorResponseSchema.extend({
|
|
7483
|
-
code: z18.string().optional().describe("Stable machine-readable failure code: artifact_not_found, artifact_kind_mismatch, artifact_moved, restore_point_not_found, comment_not_found, invalid_artifact, invalid_comment, invalid_state, name_required (a shared link's guest gives their name before commenting), state_full, comments_full, not_allowed, not_shared (it exists but neither a conversation nor an object you read shares it), read_only (you only read it), query_not_found, query_invalid (the ontology no longer admits the query), preview_not_found (the board has no preview yet, or will have none), execution_lost (a run token's run ended or moved to another runner), or storage_unavailable."),
|
|
7885
|
+
code: z18.string().optional().describe("Stable machine-readable failure code: artifact_not_found, artifact_kind_mismatch, artifact_moved, restore_point_not_found, comment_not_found, invalid_artifact, invalid_comment, invalid_state, name_required (a shared link's guest gives their name before commenting), state_full, comments_full, not_allowed, not_shared (it exists but neither a conversation nor an object you read shares it), read_only (you only read it), query_not_found, holder_not_found (no one object of the type a designed document names that you read holds it), query_invalid (the ontology no longer admits the query), preview_not_found (the board has no preview yet, or will have none), pdf_not_found (the document is not printed yet: ask for it first), pdf_unavailable (the project has no sandboxes to print in), execution_lost (a run token's run ended or moved to another runner), or storage_unavailable."),
|
|
7484
7886
|
latest: z18.object({
|
|
7485
7887
|
version: z18.number().int(),
|
|
7486
7888
|
revision: z18.number().int(),
|
|
@@ -7809,7 +8211,8 @@ var EventExecutorSchema = z21.discriminatedUnion("type", [
|
|
|
7809
8211
|
z21.object({ type: z21.literal("ontology.recover"), recoveryId: z21.string() }),
|
|
7810
8212
|
z21.object({ type: z21.literal("ontology.indexVectors"), indexingId: z21.string() })
|
|
7811
8213
|
])
|
|
7812
|
-
})
|
|
8214
|
+
}),
|
|
8215
|
+
z21.object({ type: z21.literal("script"), runId: z21.string(), path: z21.string() })
|
|
7813
8216
|
]);
|
|
7814
8217
|
var StoredAuthorableEventBaseSchema = StoredEventBaseSchema.extend({
|
|
7815
8218
|
correlationId: z21.string().optional(),
|
|
@@ -10059,7 +10462,8 @@ async function versionResponse(host, version, options = {}) {
|
|
|
10059
10462
|
const statuses = stored && options.previews === false ? new Map([...stored.keys()].map((board) => [board, "none"])) : stored;
|
|
10060
10463
|
return {
|
|
10061
10464
|
...versionBody(version),
|
|
10062
|
-
...statuses ? { boardPreviews: Object.fromEntries(statuses) } : {}
|
|
10465
|
+
...statuses ? { boardPreviews: Object.fromEntries(statuses) } : {},
|
|
10466
|
+
...host.sandboxes && documentPdfKey(version) ? { printable: true } : {}
|
|
10063
10467
|
};
|
|
10064
10468
|
}
|
|
10065
10469
|
async function serializeChange(host, change) {
|
|
@@ -10141,6 +10545,7 @@ function handleArtifactRouteError(error, set) {
|
|
|
10141
10545
|
switch (error.code) {
|
|
10142
10546
|
case "artifact_not_found":
|
|
10143
10547
|
case "comment_not_found":
|
|
10548
|
+
case "holder_not_found":
|
|
10144
10549
|
case "query_not_found":
|
|
10145
10550
|
case "restore_point_not_found":
|
|
10146
10551
|
set.status = 404;
|
|
@@ -10165,6 +10570,7 @@ function handleArtifactRouteError(error, set) {
|
|
|
10165
10570
|
case "read_only":
|
|
10166
10571
|
set.status = 403;
|
|
10167
10572
|
break;
|
|
10573
|
+
case "pdf_unavailable":
|
|
10168
10574
|
case "storage_unavailable":
|
|
10169
10575
|
set.status = 501;
|
|
10170
10576
|
break;
|
|
@@ -10293,6 +10699,36 @@ async function artifactBoardPreviewResponse(host, context) {
|
|
|
10293
10699
|
return handleArtifactRouteError(error, context.set);
|
|
10294
10700
|
}
|
|
10295
10701
|
}
|
|
10702
|
+
async function artifactPdfResponse(host, context) {
|
|
10703
|
+
try {
|
|
10704
|
+
const { artifactId } = context.params;
|
|
10705
|
+
const number = versionParam(context.params.version);
|
|
10706
|
+
const sixb = requireRequestSixb(context);
|
|
10707
|
+
const version = await sixb.artifacts.getVersion(artifactId, number);
|
|
10708
|
+
if (!version)
|
|
10709
|
+
return await refusal2(context, artifactId, context.set);
|
|
10710
|
+
const pdf = await sixb.artifacts.pdf(artifactId, {
|
|
10711
|
+
version: number,
|
|
10712
|
+
print: false,
|
|
10713
|
+
...context.query.key ? { key: context.query.key } : {}
|
|
10714
|
+
});
|
|
10715
|
+
const response = pdf?.status === "ready" && await createFileContentResponse({
|
|
10716
|
+
blobStorage: host.blobStorage,
|
|
10717
|
+
fileRef: pdf.file,
|
|
10718
|
+
request: context.request,
|
|
10719
|
+
disposition: "attachment"
|
|
10720
|
+
});
|
|
10721
|
+
if (!response) {
|
|
10722
|
+
context.set.status = 404;
|
|
10723
|
+
context.set.headers["cache-control"] = "no-store";
|
|
10724
|
+
return { error: "PDF not found", code: "pdf_not_found" };
|
|
10725
|
+
}
|
|
10726
|
+
response.headers.set("cache-control", number !== "latest" && version.frozenAt ? "private, max-age=31536000, immutable" : "private, no-cache");
|
|
10727
|
+
return response;
|
|
10728
|
+
} catch (error) {
|
|
10729
|
+
return handleArtifactRouteError(error, context.set);
|
|
10730
|
+
}
|
|
10731
|
+
}
|
|
10296
10732
|
function seesBoardPreviews(context, version) {
|
|
10297
10733
|
return !requestAuthState(context).sharedSession || !boardsReadLiveData(version);
|
|
10298
10734
|
}
|
|
@@ -10626,7 +11062,7 @@ function registerArtifactRoutes(app, host) {
|
|
|
10626
11062
|
},
|
|
10627
11063
|
detail: {
|
|
10628
11064
|
summary: "List an artifact's comments",
|
|
10629
|
-
description: "Every comment and reply, oldest first, resolved ones included. Whoever reads the artifact reads them.",
|
|
11065
|
+
description: "Every comment and reply, oldest first, resolved ones included. Whoever reads the artifact reads them; a shared link's guest reads only the threads started by a guest of the same link, with every reply in them.",
|
|
10630
11066
|
tags: [OPENAPI_TAGS.artifacts.name],
|
|
10631
11067
|
operationId: "listArtifactComments",
|
|
10632
11068
|
security: accessTokenSecurityRequirement("listArtifactComments")
|
|
@@ -10659,7 +11095,7 @@ function registerArtifactRoutes(app, host) {
|
|
|
10659
11095
|
},
|
|
10660
11096
|
detail: {
|
|
10661
11097
|
summary: "Comment on an artifact",
|
|
10662
|
-
description: "Adds a comment, or a reply with parentId, as the caller. Whoever reads the artifact may, a shared link's guest included, under the name they gave its session (400 name_required until they give one). A canvas's comment can be about one of its boards, or an element of a board by its address. Readers receive artifact.commented.",
|
|
11098
|
+
description: "Adds a comment, or a reply with parentId, as the caller. Whoever reads the artifact may, a shared link's guest included, under the name they gave its session (400 name_required until they give one), and replies only in a thread they read (404 comment_not_found otherwise). A canvas's comment can be about one of its boards, or an element of a board by its address. Readers of the thread receive artifact.commented.",
|
|
10663
11099
|
tags: [OPENAPI_TAGS.artifacts.name],
|
|
10664
11100
|
operationId: "addArtifactComment",
|
|
10665
11101
|
security: accessTokenSecurityRequirement("addArtifactComment")
|
|
@@ -10870,6 +11306,59 @@ function registerArtifactRoutes(app, host) {
|
|
|
10870
11306
|
operationId: "getArtifactVersion",
|
|
10871
11307
|
security: accessTokenSecurityRequirement("getArtifactVersion")
|
|
10872
11308
|
}
|
|
11309
|
+
}).post("/api/artifacts/:artifactId/versions/:version/pdf", async (context) => {
|
|
11310
|
+
try {
|
|
11311
|
+
const { artifactId } = context.params;
|
|
11312
|
+
const pdf = await requireRequestSixb(context).artifacts.pdf(artifactId, {
|
|
11313
|
+
version: versionParam(context.params.version),
|
|
11314
|
+
retry: context.query.retry === "true",
|
|
11315
|
+
...context.query.key ? { key: context.query.key } : {}
|
|
11316
|
+
});
|
|
11317
|
+
if (!pdf)
|
|
11318
|
+
return await refusal2(context, artifactId, context.set);
|
|
11319
|
+
if (pdf.status !== "ready")
|
|
11320
|
+
return pdf;
|
|
11321
|
+
const { file: _file, ...ready } = pdf;
|
|
11322
|
+
return ready;
|
|
11323
|
+
} catch (error) {
|
|
11324
|
+
return handleArtifactRouteError(error, context.set);
|
|
11325
|
+
}
|
|
11326
|
+
}, {
|
|
11327
|
+
params: ArtifactVersionParamsSchema,
|
|
11328
|
+
query: ArtifactPdfQuerySchema,
|
|
11329
|
+
response: {
|
|
11330
|
+
200: ArtifactPdfResponseSchema,
|
|
11331
|
+
400: ArtifactErrorResponseSchema,
|
|
11332
|
+
403: ArtifactErrorResponseSchema,
|
|
11333
|
+
404: ArtifactErrorResponseSchema,
|
|
11334
|
+
501: ArtifactErrorResponseSchema
|
|
11335
|
+
},
|
|
11336
|
+
detail: {
|
|
11337
|
+
summary: "Print a designed document to PDF",
|
|
11338
|
+
description: "Answers ready once the version is printed, and printing until then, having asked for it: ask again after a few seconds, then get it. Failed with why when it could not be printed; retry=true asks again. A document that shows live data answers with a key: ask again and get it with that key, which names the values the first ask printed. It prints as its stylesheets' @page rule lays it out, in a sandbox of the project. Whoever reads the artifact may ask. 400 invalid_artifact when the version is not a designed document; 501 pdf_unavailable in a project without sandboxes.",
|
|
11339
|
+
tags: [OPENAPI_TAGS.artifacts.name],
|
|
11340
|
+
operationId: "printArtifactPdf",
|
|
11341
|
+
security: accessTokenSecurityRequirement("printArtifactPdf")
|
|
11342
|
+
}
|
|
11343
|
+
}).get("/api/artifacts/:artifactId/versions/:version/pdf", async (context) => artifactPdfResponse(host, context), {
|
|
11344
|
+
params: ArtifactVersionParamsSchema,
|
|
11345
|
+
query: ArtifactPdfDownloadQuerySchema,
|
|
11346
|
+
detail: {
|
|
11347
|
+
summary: "Get a designed document's PDF",
|
|
11348
|
+
description: "The version printed to PDF, with the values its fields read as the caller reads them, as a download named after the title it printed with: for a document that shows live data, those its POST's key names. 404 pdf_not_found until it is printed: ask for it with POST first. A frozen version's PDF never changes, and is cached as such.",
|
|
11349
|
+
tags: [OPENAPI_TAGS.artifacts.name],
|
|
11350
|
+
operationId: "getArtifactPdf",
|
|
11351
|
+
security: accessTokenSecurityRequirement("getArtifactPdf"),
|
|
11352
|
+
responses: {
|
|
11353
|
+
200: {
|
|
11354
|
+
description: "The PDF",
|
|
11355
|
+
content: { "application/pdf": { schema: { type: "string", format: "binary" } } }
|
|
11356
|
+
},
|
|
11357
|
+
304: { description: "The PDF is unchanged; reuse the privately cached one" },
|
|
11358
|
+
403: artifactErrorResponse(403),
|
|
11359
|
+
404: artifactErrorResponse(404)
|
|
11360
|
+
}
|
|
11361
|
+
}
|
|
10873
11362
|
}).get("/api/artifacts/:artifactId/versions/:version/boards/:board/preview", async (context) => artifactBoardPreviewResponse(host, context), {
|
|
10874
11363
|
params: ArtifactBoardPreviewParamsSchema,
|
|
10875
11364
|
query: ArtifactBoardPreviewQuerySchema,
|
|
@@ -10910,7 +11399,7 @@ function registerArtifactRoutes(app, host) {
|
|
|
10910
11399
|
params: ArtifactQueryParamsSchema,
|
|
10911
11400
|
detail: {
|
|
10912
11401
|
summary: "Run an artifact's query",
|
|
10913
|
-
description: `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.`,
|
|
11402
|
+
description: `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. A designed document's "holder" is the object that holds it, of the type it names, with the links its fields read through: 404 holder_not_found when no one such object the caller reads holds it.`,
|
|
10914
11403
|
tags: [OPENAPI_TAGS.artifacts.name],
|
|
10915
11404
|
operationId: "getArtifactQuery",
|
|
10916
11405
|
security: accessTokenSecurityRequirement("getArtifactQuery"),
|
|
@@ -13037,7 +13526,7 @@ function registerModelGenerationRoutes(app, host) {
|
|
|
13037
13526
|
model: entry.model,
|
|
13038
13527
|
signal: request.signal
|
|
13039
13528
|
});
|
|
13040
|
-
return TranscriptionSchema.parse({ ...result(entry, call),
|
|
13529
|
+
return TranscriptionSchema.parse({ ...result(entry, call), ...call.output });
|
|
13041
13530
|
} catch (error) {
|
|
13042
13531
|
return generationError(error, set);
|
|
13043
13532
|
}
|
|
@@ -13184,7 +13673,7 @@ function registerObservedAgentThreadRoutes(app, host) {
|
|
|
13184
13673
|
return threadNotFound(context.set);
|
|
13185
13674
|
}
|
|
13186
13675
|
const query = AgentMessagesQuerySchema.parse(context.query);
|
|
13187
|
-
return
|
|
13676
|
+
return await readThreadMessages(host, storage, thread, query);
|
|
13188
13677
|
} catch (error) {
|
|
13189
13678
|
return handleAgentRouteError(error, context.set);
|
|
13190
13679
|
}
|
|
@@ -13237,7 +13726,7 @@ function registerObservedAgentThreadRoutes(app, host) {
|
|
|
13237
13726
|
return threadNotFound(context.set);
|
|
13238
13727
|
}
|
|
13239
13728
|
return AgentRunListResponseSchema.parse({
|
|
13240
|
-
runs: result.runs.map(serializeAgentRun),
|
|
13729
|
+
runs: result.runs.map((run) => serializeAgentRun(run)),
|
|
13241
13730
|
hasMore: result.hasMore,
|
|
13242
13731
|
total: result.total
|
|
13243
13732
|
});
|
|
@@ -13865,6 +14354,7 @@ var ObjectProjectionSchema = z33.object({
|
|
|
13865
14354
|
users: z33.record(z33.enum(["email", "id"])).optional(),
|
|
13866
14355
|
links: z33.record(ForeignKeyDescriptorSchema),
|
|
13867
14356
|
conflictResolution: SourceEditConflictResolutionSchema,
|
|
14357
|
+
missing: z33.literal("remove").optional(),
|
|
13868
14358
|
latestRun: ProjectionRunSchema.nullable()
|
|
13869
14359
|
});
|
|
13870
14360
|
var LinkProjectionSchema = z33.object({
|
|
@@ -14753,7 +15243,7 @@ var StatusResponseSchema = z37.object({
|
|
|
14753
15243
|
});
|
|
14754
15244
|
|
|
14755
15245
|
// src/routes/status.ts
|
|
14756
|
-
function registerStatusRoutes(app, host) {
|
|
15246
|
+
function registerStatusRoutes(app, host, options = {}) {
|
|
14757
15247
|
app.get("/health", () => ({ status: "ok" }), {
|
|
14758
15248
|
response: { 200: HealthResponseSchema },
|
|
14759
15249
|
detail: {
|
|
@@ -14764,6 +15254,14 @@ function registerStatusRoutes(app, host) {
|
|
|
14764
15254
|
}
|
|
14765
15255
|
});
|
|
14766
15256
|
app.get("/ready", async ({ set }) => {
|
|
15257
|
+
if (options.isStopping?.()) {
|
|
15258
|
+
set.status = 503;
|
|
15259
|
+
return {
|
|
15260
|
+
status: "unready",
|
|
15261
|
+
storage: { reachable: false, schemaValid: false },
|
|
15262
|
+
reason: "Server is shutting down."
|
|
15263
|
+
};
|
|
15264
|
+
}
|
|
14767
15265
|
const readiness = await host.checkReadiness();
|
|
14768
15266
|
if (readiness.status === "unready")
|
|
14769
15267
|
set.status = 503;
|
|
@@ -14794,6 +15292,9 @@ function registerStatusRoutes(app, host) {
|
|
|
14794
15292
|
});
|
|
14795
15293
|
}
|
|
14796
15294
|
|
|
15295
|
+
// src/routes/syncs.ts
|
|
15296
|
+
import { isOAuthConnectorDefinition as isOAuthConnectorDefinition3 } from "@sixb/core/internal/connector-connections";
|
|
15297
|
+
|
|
14797
15298
|
// src/schemas/syncs.ts
|
|
14798
15299
|
import {
|
|
14799
15300
|
SYNC_RUN_FAILURE_CODES
|
|
@@ -14807,6 +15308,7 @@ var SyncRunStatusSchema = z38.enum(["queued", "running", "succeeded", "failed",
|
|
|
14807
15308
|
var SyncModeSchema = z38.enum(["snapshot", "append", "merge"]);
|
|
14808
15309
|
var SyncRunsQuerySchema = z38.object({
|
|
14809
15310
|
syncId: z38.string().optional(),
|
|
15311
|
+
connectionId: z38.string().optional(),
|
|
14810
15312
|
datasetId: z38.string().optional(),
|
|
14811
15313
|
status: SyncRunStatusSchema.optional(),
|
|
14812
15314
|
startedAfter: z38.string().optional(),
|
|
@@ -14816,6 +15318,7 @@ var SyncRunsQuerySchema = z38.object({
|
|
|
14816
15318
|
order: z38.enum(["asc", "desc"]).optional()
|
|
14817
15319
|
});
|
|
14818
15320
|
var RequestSyncRunBodySchema = z38.object({
|
|
15321
|
+
connectionId: z38.string().optional(),
|
|
14819
15322
|
expectedLatestVersionId: z38.string().optional(),
|
|
14820
15323
|
commitMessage: z38.string().optional()
|
|
14821
15324
|
});
|
|
@@ -14827,6 +15330,7 @@ var SyncRunSchema = z38.object({
|
|
|
14827
15330
|
id: z38.string(),
|
|
14828
15331
|
projectId: z38.string(),
|
|
14829
15332
|
syncId: z38.string(),
|
|
15333
|
+
connectionId: z38.string().optional(),
|
|
14830
15334
|
datasetId: z38.string(),
|
|
14831
15335
|
mode: SyncModeSchema,
|
|
14832
15336
|
status: SyncRunStatusSchema,
|
|
@@ -14843,6 +15347,33 @@ var SyncRunSchema = z38.object({
|
|
|
14843
15347
|
commitMessage: z38.string().optional(),
|
|
14844
15348
|
error: SyncRunFailureSchema.optional()
|
|
14845
15349
|
});
|
|
15350
|
+
var SyncAccountConnectionSchema = z38.object({
|
|
15351
|
+
id: z38.string(),
|
|
15352
|
+
owner: z38.discriminatedUnion("type", [
|
|
15353
|
+
z38.object({ type: z38.literal("project") }),
|
|
15354
|
+
z38.object({ type: z38.literal("user"), id: z38.string() })
|
|
15355
|
+
]),
|
|
15356
|
+
slot: z38.string(),
|
|
15357
|
+
account: z38.object({ id: z38.string(), label: z38.string() })
|
|
15358
|
+
});
|
|
15359
|
+
var ConnectorAccountSchema2 = z38.object({
|
|
15360
|
+
connection: SyncAccountConnectionSchema,
|
|
15361
|
+
latestRuns: z38.array(SyncRunSchema)
|
|
15362
|
+
});
|
|
15363
|
+
var ConnectorAccountListResponseSchema = z38.object({
|
|
15364
|
+
accounts: z38.array(ConnectorAccountSchema2)
|
|
15365
|
+
});
|
|
15366
|
+
var ConnectorAccountsParamsSchema = z38.object({
|
|
15367
|
+
connectorId: z38.string().min(1)
|
|
15368
|
+
});
|
|
15369
|
+
var SyncAccountSummarySchema = z38.object({
|
|
15370
|
+
total: z38.number(),
|
|
15371
|
+
running: z38.number(),
|
|
15372
|
+
needsReconnecting: z38.number(),
|
|
15373
|
+
failing: z38.number(),
|
|
15374
|
+
synced: z38.number(),
|
|
15375
|
+
lastSyncedAt: z38.string().optional()
|
|
15376
|
+
});
|
|
14846
15377
|
var SyncSchema = z38.object({
|
|
14847
15378
|
id: z38.string(),
|
|
14848
15379
|
mode: SyncModeSchema,
|
|
@@ -14855,19 +15386,31 @@ var SyncSchema = z38.object({
|
|
|
14855
15386
|
dataset: DatasetDefinitionSchema
|
|
14856
15387
|
}),
|
|
14857
15388
|
triggers: z38.array(SyncTriggerSchema),
|
|
14858
|
-
latestRun: SyncRunSchema.nullable()
|
|
15389
|
+
latestRun: SyncRunSchema.nullable(),
|
|
15390
|
+
accounts: SyncAccountSummarySchema.optional()
|
|
15391
|
+
});
|
|
15392
|
+
var ConnectionSyncRunsParamsSchema = z38.object({
|
|
15393
|
+
connectorId: z38.string().min(1),
|
|
15394
|
+
connectionId: z38.string().min(1)
|
|
15395
|
+
});
|
|
15396
|
+
var ConnectionSyncRunsResponseSchema = z38.object({
|
|
15397
|
+
runs: z38.array(SyncRunSchema)
|
|
14859
15398
|
});
|
|
14860
15399
|
var SyncRunListResponseSchema = z38.object({
|
|
14861
15400
|
runs: z38.array(SyncRunSchema),
|
|
14862
15401
|
hasMore: z38.boolean(),
|
|
14863
15402
|
total: z38.number()
|
|
14864
15403
|
});
|
|
14865
|
-
var
|
|
15404
|
+
var RequestedSyncRunSchema = z38.object({
|
|
14866
15405
|
runId: z38.string(),
|
|
14867
15406
|
jobId: z38.string(),
|
|
14868
15407
|
syncId: z38.string(),
|
|
15408
|
+
connectionId: z38.string().optional(),
|
|
14869
15409
|
queuedAt: z38.string()
|
|
14870
15410
|
});
|
|
15411
|
+
var RequestSyncRunResponseSchema = z38.object({
|
|
15412
|
+
runs: z38.array(RequestedSyncRunSchema)
|
|
15413
|
+
});
|
|
14871
15414
|
|
|
14872
15415
|
// src/routes/syncs.ts
|
|
14873
15416
|
function serializeSyncRun(run) {
|
|
@@ -14875,6 +15418,7 @@ function serializeSyncRun(run) {
|
|
|
14875
15418
|
id: run.id,
|
|
14876
15419
|
projectId: run.projectId,
|
|
14877
15420
|
syncId: run.syncId,
|
|
15421
|
+
connectionId: run.connectionId,
|
|
14878
15422
|
datasetId: run.datasetId,
|
|
14879
15423
|
mode: run.mode,
|
|
14880
15424
|
status: run.status,
|
|
@@ -14901,7 +15445,48 @@ async function getLatestSyncRuns(sixb, syncIds) {
|
|
|
14901
15445
|
const result = await sixb.syncs.runs.listLatest(syncIds);
|
|
14902
15446
|
return new Map(result.runs.map((run) => [run.syncId, serializeSyncRun(run)]));
|
|
14903
15447
|
}
|
|
14904
|
-
function
|
|
15448
|
+
function serializeAccount(account) {
|
|
15449
|
+
const { id, owner, slot, account: candidate } = account.connection;
|
|
15450
|
+
return {
|
|
15451
|
+
connection: { id, owner, slot, account: { id: candidate.id, label: candidate.label } },
|
|
15452
|
+
latestRuns: account.latestRuns.map(serializeSyncRun)
|
|
15453
|
+
};
|
|
15454
|
+
}
|
|
15455
|
+
function connectorAccounts(sixb) {
|
|
15456
|
+
const byConnector = new Map;
|
|
15457
|
+
return (connectorId) => {
|
|
15458
|
+
let accounts = byConnector.get(connectorId);
|
|
15459
|
+
if (!accounts) {
|
|
15460
|
+
accounts = sixb.syncs.accounts.list(connectorId);
|
|
15461
|
+
byConnector.set(connectorId, accounts);
|
|
15462
|
+
}
|
|
15463
|
+
return accounts;
|
|
15464
|
+
};
|
|
15465
|
+
}
|
|
15466
|
+
async function summarizeAccounts(sync, accountsOf) {
|
|
15467
|
+
if (!isOAuthConnectorDefinition3(sync.connector))
|
|
15468
|
+
return;
|
|
15469
|
+
return summarizeSyncAccounts(sync.id, await accountsOf(sync.connector.id));
|
|
15470
|
+
}
|
|
15471
|
+
function summarizeSyncAccounts(syncId, accounts) {
|
|
15472
|
+
const latest = accounts.flatMap(({ latestRuns }) => latestRuns.filter((run) => run.syncId === syncId));
|
|
15473
|
+
const count = (matches) => latest.filter(matches).length;
|
|
15474
|
+
const reconnect = (run) => run.error?.code === "connector.authorization_required";
|
|
15475
|
+
const synced = latest.filter((run) => run.status === "succeeded");
|
|
15476
|
+
const lastSyncedAt = synced.reduce((last, run) => {
|
|
15477
|
+
const at = run.finishedAt ?? run.queuedAt;
|
|
15478
|
+
return last && last >= at ? last : at;
|
|
15479
|
+
}, undefined);
|
|
15480
|
+
return {
|
|
15481
|
+
total: accounts.length,
|
|
15482
|
+
running: count((run) => run.status === "queued" || run.status === "running"),
|
|
15483
|
+
needsReconnecting: count((run) => run.status === "failed" && reconnect(run)),
|
|
15484
|
+
failing: count((run) => run.status === "failed" && !reconnect(run)),
|
|
15485
|
+
synced: synced.length,
|
|
15486
|
+
...lastSyncedAt === undefined ? {} : { lastSyncedAt: toIsoString(lastSyncedAt) }
|
|
15487
|
+
};
|
|
15488
|
+
}
|
|
15489
|
+
function serializeSync(sync, latestRun, accounts) {
|
|
14905
15490
|
return SyncSchema.parse({
|
|
14906
15491
|
id: sync.id,
|
|
14907
15492
|
mode: sync.config.mode,
|
|
@@ -14914,7 +15499,8 @@ function serializeSync(sync, latestRun) {
|
|
|
14914
15499
|
dataset: sync.target.dataset
|
|
14915
15500
|
},
|
|
14916
15501
|
triggers: sync.triggers,
|
|
14917
|
-
latestRun
|
|
15502
|
+
latestRun,
|
|
15503
|
+
...accounts === undefined ? {} : { accounts }
|
|
14918
15504
|
});
|
|
14919
15505
|
}
|
|
14920
15506
|
function registerSyncRoutes(app, host) {
|
|
@@ -14922,7 +15508,8 @@ function registerSyncRoutes(app, host) {
|
|
|
14922
15508
|
const sixb = requireRequestSixb(context);
|
|
14923
15509
|
const syncs = sixb.syncs.list();
|
|
14924
15510
|
const latestRuns = await getLatestSyncRuns(sixb, syncs.map((sync) => sync.id));
|
|
14925
|
-
|
|
15511
|
+
const accountsOf = connectorAccounts(sixb);
|
|
15512
|
+
return Promise.all(syncs.map(async (sync) => serializeSync(sync, latestRuns.get(sync.id) ?? null, await summarizeAccounts(sync, accountsOf))));
|
|
14926
15513
|
}, {
|
|
14927
15514
|
response: { 200: SyncSchema.array() },
|
|
14928
15515
|
detail: {
|
|
@@ -14939,7 +15526,7 @@ function registerSyncRoutes(app, host) {
|
|
|
14939
15526
|
set.status = 404;
|
|
14940
15527
|
return { error: "Sync not found" };
|
|
14941
15528
|
}
|
|
14942
|
-
return serializeSync(sync, await getLatestSyncRun(sixb, sync.id));
|
|
15529
|
+
return serializeSync(sync, await getLatestSyncRun(sixb, sync.id), await summarizeAccounts(sync, connectorAccounts(sixb)));
|
|
14943
15530
|
}, {
|
|
14944
15531
|
params: SyncParamsSchema,
|
|
14945
15532
|
response: { 200: SyncSchema, 404: ErrorResponseSchema },
|
|
@@ -14949,6 +15536,35 @@ function registerSyncRoutes(app, host) {
|
|
|
14949
15536
|
operationId: "getSync",
|
|
14950
15537
|
security: accessTokenSecurityRequirement("getSync")
|
|
14951
15538
|
}
|
|
15539
|
+
}).get("/api/connectors/:connectorId/accounts", async (context) => {
|
|
15540
|
+
const { params } = context;
|
|
15541
|
+
const sixb = requireRequestSixb(context);
|
|
15542
|
+
const accounts = await sixb.syncs.accounts.list(params.connectorId);
|
|
15543
|
+
return { accounts: accounts.map(serializeAccount) };
|
|
15544
|
+
}, {
|
|
15545
|
+
params: ConnectorAccountsParamsSchema,
|
|
15546
|
+
response: { 200: ConnectorAccountListResponseSchema },
|
|
15547
|
+
detail: {
|
|
15548
|
+
summary: "List a connector's accounts and how they synced",
|
|
15549
|
+
description: "On an OAuth connector, each connected account you may see, with the latest run of each of its syncs you may run. Empty for a static connector.",
|
|
15550
|
+
tags: [OPENAPI_TAGS.connectorConnections.name],
|
|
15551
|
+
operationId: "listConnectorAccounts",
|
|
15552
|
+
security: accessTokenSecurityRequirement("listConnectorAccounts")
|
|
15553
|
+
}
|
|
15554
|
+
}).get("/api/connectors/:connectorId/connections/:connectionId/sync-runs", async (context) => {
|
|
15555
|
+
const { params } = context;
|
|
15556
|
+
const sixb = requireRequestSixb(context);
|
|
15557
|
+
const runs = await sixb.syncs.accounts.latestRuns(params.connectorId, params.connectionId);
|
|
15558
|
+
return { runs: runs.map(serializeSyncRun) };
|
|
15559
|
+
}, {
|
|
15560
|
+
params: ConnectionSyncRunsParamsSchema,
|
|
15561
|
+
response: { 200: ConnectionSyncRunsResponseSchema },
|
|
15562
|
+
detail: {
|
|
15563
|
+
summary: "Latest sync runs of a connection",
|
|
15564
|
+
description: "The latest run of each sync of one connection: your own, or anyone's with can.manage on its connector. Empty for a connection you don't see.",
|
|
15565
|
+
tags: [OPENAPI_TAGS.connectorConnections.name],
|
|
15566
|
+
operationId: "listConnectorConnectionSyncRuns"
|
|
15567
|
+
}
|
|
14952
15568
|
}).get("/api/sync-runs", async (context) => {
|
|
14953
15569
|
const { query, set } = context;
|
|
14954
15570
|
const sixb = requireRequestSixb(context);
|
|
@@ -14960,6 +15576,7 @@ function registerSyncRoutes(app, host) {
|
|
|
14960
15576
|
}
|
|
14961
15577
|
const result = await sixb.syncs.runs.list({
|
|
14962
15578
|
syncId: parsed.syncId,
|
|
15579
|
+
...parsed.connectionId === undefined ? {} : { connectionId: parsed.connectionId },
|
|
14963
15580
|
datasetId: parsed.datasetId,
|
|
14964
15581
|
statuses: parsed.status ? [parsed.status] : undefined,
|
|
14965
15582
|
startedAfter: parseDate(parsed.startedAfter),
|
|
@@ -14997,10 +15614,13 @@ function registerSyncRoutes(app, host) {
|
|
|
14997
15614
|
const result = await sixb.syncs.request({ syncId: params.syncId, ...parsedBody });
|
|
14998
15615
|
set.status = 202;
|
|
14999
15616
|
return {
|
|
15000
|
-
|
|
15001
|
-
|
|
15002
|
-
|
|
15003
|
-
|
|
15617
|
+
runs: result.runs.map((run) => ({
|
|
15618
|
+
runId: run.runId,
|
|
15619
|
+
jobId: run.jobId ?? "",
|
|
15620
|
+
syncId: run.syncId,
|
|
15621
|
+
connectionId: run.connectionId,
|
|
15622
|
+
queuedAt: run.queuedAt
|
|
15623
|
+
}))
|
|
15004
15624
|
};
|
|
15005
15625
|
} catch (error) {
|
|
15006
15626
|
return handleRouteError(error, set);
|
|
@@ -16420,7 +17040,7 @@ function registerHttpRoutes(app, host, options) {
|
|
|
16420
17040
|
registerModelCallRoutes(app, host);
|
|
16421
17041
|
registerModelGenerationRoutes(app, host);
|
|
16422
17042
|
registerProjectRoutes(app, host);
|
|
16423
|
-
registerStatusRoutes(app, host);
|
|
17043
|
+
registerStatusRoutes(app, host, { isStopping: options.isStopping });
|
|
16424
17044
|
registerConnectorRoutes(app, host);
|
|
16425
17045
|
registerConnectorConnectionRoutes(app, host);
|
|
16426
17046
|
registerConnectorConnectionRunRoutes(app, host, options.connectorConnections);
|
|
@@ -16439,6 +17059,7 @@ function registerHttpRoutes(app, host, options) {
|
|
|
16439
17059
|
registerFileDownloadRoutes(app, host);
|
|
16440
17060
|
registerActionRunRoutes(app, host);
|
|
16441
17061
|
registerAgentRoutes(app, host);
|
|
17062
|
+
registerAgentThreadReadRoutes(app, host);
|
|
16442
17063
|
registerAgentChildRoutes(app, host);
|
|
16443
17064
|
registerAgentRunnerRoutes(app, host);
|
|
16444
17065
|
registerAgentComputerRoutes(app, host);
|
|
@@ -19284,7 +19905,9 @@ import { BrokerCursorExpiredError } from "@sixb/core/broker";
|
|
|
19284
19905
|
import {
|
|
19285
19906
|
agentActivityStreamDefinition,
|
|
19286
19907
|
agentRunStreamDefinition,
|
|
19287
|
-
agentRunStreamId as agentRunStreamId3
|
|
19908
|
+
agentRunStreamId as agentRunStreamId3,
|
|
19909
|
+
coveredBySteps,
|
|
19910
|
+
readAgentRunSteps
|
|
19288
19911
|
} from "@sixb/core/internal/agents/streams";
|
|
19289
19912
|
import { z as z43 } from "zod";
|
|
19290
19913
|
|
|
@@ -19454,12 +20077,17 @@ async function subscribeAgentStream(states, server, ws, message) {
|
|
|
19454
20077
|
states.set(wsStateKey(ws), state);
|
|
19455
20078
|
const buffered = [];
|
|
19456
20079
|
let live = false;
|
|
20080
|
+
let steps = null;
|
|
20081
|
+
const send = (records) => {
|
|
20082
|
+
const current = steps;
|
|
20083
|
+
sendRecords(ws, current ? records.filter((record) => !coveredBySteps(current, record.payload)) : records);
|
|
20084
|
+
};
|
|
19457
20085
|
const receive = (records) => {
|
|
19458
20086
|
if (!live) {
|
|
19459
20087
|
buffered.push(...records);
|
|
19460
20088
|
return;
|
|
19461
20089
|
}
|
|
19462
|
-
|
|
20090
|
+
send(records);
|
|
19463
20091
|
};
|
|
19464
20092
|
let resumedFromEarliest = false;
|
|
19465
20093
|
try {
|
|
@@ -19497,13 +20125,34 @@ async function subscribeAgentStream(states, server, ws, message) {
|
|
|
19497
20125
|
runId: message.runId,
|
|
19498
20126
|
afterCursor: resumedFromEarliest ? null : message.afterCursor ?? null
|
|
19499
20127
|
});
|
|
19500
|
-
|
|
20128
|
+
if (message.afterCursor === undefined || resumedFromEarliest) {
|
|
20129
|
+
steps = await readRunSteps(server, sixb, message.runId);
|
|
20130
|
+
if (steps)
|
|
20131
|
+
safeSend(ws, { type: "run.steps", event: steps });
|
|
20132
|
+
}
|
|
20133
|
+
send(buffered.splice(0));
|
|
19501
20134
|
if (!await sendRunSnapshot(sixb, ws, message.runId)) {
|
|
19502
20135
|
stopSubscription(state);
|
|
19503
20136
|
return;
|
|
19504
20137
|
}
|
|
19505
20138
|
live = true;
|
|
19506
|
-
|
|
20139
|
+
send(buffered.splice(0));
|
|
20140
|
+
}
|
|
20141
|
+
async function readRunSteps(server, sixb, runId) {
|
|
20142
|
+
try {
|
|
20143
|
+
const run = await sixb.agent.runs.getById(runId);
|
|
20144
|
+
if (!run || run.status !== "queued" && run.status !== "running")
|
|
20145
|
+
return null;
|
|
20146
|
+
const host = server.getHost();
|
|
20147
|
+
return await readAgentRunSteps(host.broker, {
|
|
20148
|
+
projectId: host.id,
|
|
20149
|
+
runId,
|
|
20150
|
+
attempt: run.attempt
|
|
20151
|
+
});
|
|
20152
|
+
} catch (error) {
|
|
20153
|
+
console.error(`[SixbServer] Agent run '${runId}' finished steps could not be read:`, error);
|
|
20154
|
+
return null;
|
|
20155
|
+
}
|
|
19507
20156
|
}
|
|
19508
20157
|
async function subscribeAgentActivity(states, server, ws) {
|
|
19509
20158
|
const host = server.getHost();
|
|
@@ -19677,9 +20326,11 @@ import {
|
|
|
19677
20326
|
AGENT_PRESENCE_MS,
|
|
19678
20327
|
artifactLiveStream,
|
|
19679
20328
|
artifactPresenceStream,
|
|
20329
|
+
keepsDocument,
|
|
19680
20330
|
loadArtifactDocument,
|
|
19681
20331
|
mergeIntoDocument,
|
|
19682
20332
|
parseArtifactLiveRecord,
|
|
20333
|
+
readChange,
|
|
19683
20334
|
readDocumentState,
|
|
19684
20335
|
readLiveFiles,
|
|
19685
20336
|
sameArtifactFiles,
|
|
@@ -19721,6 +20372,7 @@ class LiveRoom {
|
|
|
19721
20372
|
shadow;
|
|
19722
20373
|
state = "saved";
|
|
19723
20374
|
error;
|
|
20375
|
+
refused = false;
|
|
19724
20376
|
failure;
|
|
19725
20377
|
attempts = 0;
|
|
19726
20378
|
idle;
|
|
@@ -19753,7 +20405,7 @@ class LiveRoom {
|
|
|
19753
20405
|
const artifact = await storage.get({ projectId: host.projectId, id: artifactId });
|
|
19754
20406
|
if (!artifact)
|
|
19755
20407
|
return "not_found";
|
|
19756
|
-
if (artifact.kind
|
|
20408
|
+
if (!keepsDocument(artifact.kind))
|
|
19757
20409
|
return "not_live";
|
|
19758
20410
|
const version = await storage.getVersion({
|
|
19759
20411
|
projectId: host.projectId,
|
|
@@ -20002,6 +20654,7 @@ class LiveRoom {
|
|
|
20002
20654
|
this.savedSnapshot = written;
|
|
20003
20655
|
this.attempts = 0;
|
|
20004
20656
|
this.error = undefined;
|
|
20657
|
+
this.refused = false;
|
|
20005
20658
|
this.failure = undefined;
|
|
20006
20659
|
this.setState(this.dirty ? "unsaved" : "saved", true);
|
|
20007
20660
|
if (this.dirty && !this.idle)
|
|
@@ -20012,8 +20665,9 @@ class LiveRoom {
|
|
|
20012
20665
|
this.attempts += 1;
|
|
20013
20666
|
this.error = error instanceof Error ? error.message : String(error);
|
|
20014
20667
|
this.failure = error;
|
|
20015
|
-
this.setState("failed", true);
|
|
20016
20668
|
const code = error instanceof ArtifactRequestError2 ? error.code : undefined;
|
|
20669
|
+
this.refused = code === "invalid_artifact";
|
|
20670
|
+
this.setState("failed", true);
|
|
20017
20671
|
if (code === "artifact_not_found") {
|
|
20018
20672
|
for (const member of [...this.members.values()]) {
|
|
20019
20673
|
member.connection.send({ type: "left", artifactId: this.artifactId, reason: "not_found" });
|
|
@@ -20120,8 +20774,7 @@ class LiveRoom {
|
|
|
20120
20774
|
}
|
|
20121
20775
|
readable(bytes) {
|
|
20122
20776
|
try {
|
|
20123
|
-
syncProtocol.readSyncMessage(decoding2.createDecoder(bytes), encoding2.createEncoder(), this.shadow, null);
|
|
20124
|
-
documentFiles(this.shadow);
|
|
20777
|
+
readChange(this.shadow, () => syncProtocol.readSyncMessage(decoding2.createDecoder(bytes), encoding2.createEncoder(), this.shadow, null));
|
|
20125
20778
|
return true;
|
|
20126
20779
|
} catch {
|
|
20127
20780
|
this.shadow.destroy();
|
|
@@ -20316,7 +20969,8 @@ class LiveRoom {
|
|
|
20316
20969
|
state: this.state,
|
|
20317
20970
|
revision: this.synced.revision,
|
|
20318
20971
|
snapshot: encodeLiveData(this.savedSnapshot),
|
|
20319
|
-
...this.state === "failed" && this.error ? { error: this.error } : {}
|
|
20972
|
+
...this.state === "failed" && this.error ? { error: this.error } : {},
|
|
20973
|
+
...this.state === "failed" && this.refused ? { refused: true } : {}
|
|
20320
20974
|
};
|
|
20321
20975
|
}
|
|
20322
20976
|
setState(state, announce = false) {
|
|
@@ -21408,6 +22062,7 @@ function registerWebSocketRoutes(app, server, sharedAccess) {
|
|
|
21408
22062
|
|
|
21409
22063
|
// src/server.ts
|
|
21410
22064
|
var MAX_WEBSOCKET_MESSAGE_BYTES = 64 * 1024;
|
|
22065
|
+
var SERVICE_RESTART_CLOSE_CODE = 1012;
|
|
21411
22066
|
function createSixbServer(options) {
|
|
21412
22067
|
return new SixbServer(options);
|
|
21413
22068
|
}
|
|
@@ -21426,10 +22081,13 @@ class SixbServer {
|
|
|
21426
22081
|
timing;
|
|
21427
22082
|
app = null;
|
|
21428
22083
|
bunServer = null;
|
|
22084
|
+
closeWebSockets = null;
|
|
22085
|
+
stopping = false;
|
|
21429
22086
|
hostsOntologyMaintenance;
|
|
21430
22087
|
flushesIngestion;
|
|
21431
22088
|
maintenance = null;
|
|
21432
22089
|
stopSweeper = null;
|
|
22090
|
+
inProgressStop = null;
|
|
21433
22091
|
constructor(options) {
|
|
21434
22092
|
this.hostRuntime = options.host;
|
|
21435
22093
|
this.port = options.port ?? 3000;
|
|
@@ -21475,10 +22133,17 @@ class SixbServer {
|
|
|
21475
22133
|
getSharedAccessOptions() {
|
|
21476
22134
|
return this.sharedAccessOptions;
|
|
21477
22135
|
}
|
|
22136
|
+
markStopping() {
|
|
22137
|
+
this.stopping = true;
|
|
22138
|
+
}
|
|
22139
|
+
isStopping() {
|
|
22140
|
+
return this.stopping;
|
|
22141
|
+
}
|
|
21478
22142
|
async start() {
|
|
21479
22143
|
if (this.app !== null || this.bunServer !== null || this.maintenance !== null) {
|
|
21480
22144
|
throw new Error("[SixbServer] Server is already running.");
|
|
21481
22145
|
}
|
|
22146
|
+
this.stopping = false;
|
|
21482
22147
|
await checkPipelineMarkings({
|
|
21483
22148
|
definitions: this.hostRuntime.definitions,
|
|
21484
22149
|
lakeStorage: this.hostRuntime.lakeStorage
|
|
@@ -21490,15 +22155,18 @@ class SixbServer {
|
|
|
21490
22155
|
this.maintenance = maintenance;
|
|
21491
22156
|
try {
|
|
21492
22157
|
this.app = createSixbApi(this);
|
|
21493
|
-
|
|
22158
|
+
const started = startApiServer(this.app, {
|
|
21494
22159
|
host: this.hostname,
|
|
21495
22160
|
port: this.port,
|
|
21496
22161
|
resolveClientAddress: this.resolveClientAddress,
|
|
21497
22162
|
timing: this.timing
|
|
21498
22163
|
});
|
|
22164
|
+
this.bunServer = started.bunServer;
|
|
22165
|
+
this.closeWebSockets = started.closeWebSockets;
|
|
21499
22166
|
} catch (error) {
|
|
21500
22167
|
this.app = null;
|
|
21501
22168
|
this.bunServer = null;
|
|
22169
|
+
this.closeWebSockets = null;
|
|
21502
22170
|
this.maintenance = null;
|
|
21503
22171
|
await maintenance?.stop();
|
|
21504
22172
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -21516,17 +22184,42 @@ class SixbServer {
|
|
|
21516
22184
|
if (ingest)
|
|
21517
22185
|
ingest.writesInline = inline;
|
|
21518
22186
|
}
|
|
21519
|
-
async stop() {
|
|
22187
|
+
async stop(options = {}) {
|
|
22188
|
+
const timeoutMs = resolveStopTimeoutMs(options.timeoutMs, ACTION_RUN_DRAIN_TIMEOUT_MS);
|
|
22189
|
+
if (this.inProgressStop) {
|
|
22190
|
+
this.inProgressStop.deadline.bringForward(timeoutMs);
|
|
22191
|
+
return this.inProgressStop.done;
|
|
22192
|
+
}
|
|
22193
|
+
const deadline = new StopDeadline(timeoutMs);
|
|
22194
|
+
const done = this.stopUntil(deadline).finally(() => {
|
|
22195
|
+
this.inProgressStop = null;
|
|
22196
|
+
});
|
|
22197
|
+
this.inProgressStop = { deadline, done };
|
|
22198
|
+
return done;
|
|
22199
|
+
}
|
|
22200
|
+
async stopUntil(deadline) {
|
|
22201
|
+
this.stopping = true;
|
|
21520
22202
|
this.setIngestFlush(false);
|
|
21521
22203
|
this.stopSweeper?.();
|
|
21522
22204
|
this.stopSweeper = null;
|
|
21523
|
-
|
|
21524
|
-
|
|
21525
|
-
|
|
21526
|
-
|
|
21527
|
-
|
|
21528
|
-
|
|
21529
|
-
|
|
22205
|
+
const bunServer = this.bunServer;
|
|
22206
|
+
const closeWebSockets = this.closeWebSockets;
|
|
22207
|
+
const app = this.app;
|
|
22208
|
+
this.bunServer = null;
|
|
22209
|
+
this.closeWebSockets = null;
|
|
22210
|
+
this.app = null;
|
|
22211
|
+
const stopAppAndSockets = async () => {
|
|
22212
|
+
try {
|
|
22213
|
+
if (app)
|
|
22214
|
+
await stopElysiaHooks(app);
|
|
22215
|
+
} finally {
|
|
22216
|
+
closeWebSockets?.();
|
|
22217
|
+
}
|
|
22218
|
+
};
|
|
22219
|
+
if (bunServer) {
|
|
22220
|
+
await drainBunServer(bunServer, deadline, stopAppAndSockets);
|
|
22221
|
+
} else {
|
|
22222
|
+
await stopAppAndSockets();
|
|
21530
22223
|
}
|
|
21531
22224
|
const maintenance = this.maintenance;
|
|
21532
22225
|
this.maintenance = null;
|
|
@@ -21566,7 +22259,7 @@ function createSixbApi(server) {
|
|
|
21566
22259
|
maxAge: 600
|
|
21567
22260
|
}));
|
|
21568
22261
|
const serveRunnerSession = agentRunSessionHandler(host);
|
|
21569
|
-
app.onRequest(async ({ request }) => await serveRunnerSession(request) ?? undefined);
|
|
22262
|
+
app.onRequest(async ({ request, server }) => await serveRunnerSession(request, server) ?? undefined);
|
|
21570
22263
|
app.onRequest(async ({ request }) => {
|
|
21571
22264
|
const runToken = requestRunToken(request);
|
|
21572
22265
|
if (runToken === undefined)
|
|
@@ -21731,6 +22424,7 @@ function createSixbApi(server) {
|
|
|
21731
22424
|
registerHttpRoutes(app, host, {
|
|
21732
22425
|
sharedAccess,
|
|
21733
22426
|
browserPolicy: apiBrowserPolicy,
|
|
22427
|
+
isStopping: () => server.isStopping(),
|
|
21734
22428
|
connectorConnections: {
|
|
21735
22429
|
resolveReturnTo: (request, returnTo) => server.resolveAuthRedirectContext(request, { returnTo }).returnTo,
|
|
21736
22430
|
resolveCallbackUrl: (request) => new URL("/auth/connectors/callback", server.resolveAuthRequestOrigin(request)).toString()
|
|
@@ -21786,6 +22480,7 @@ function rejectDisallowedBrowserOrigin(request, policy) {
|
|
|
21786
22480
|
});
|
|
21787
22481
|
}
|
|
21788
22482
|
function startApiServer(app, options) {
|
|
22483
|
+
const openSockets = new Set;
|
|
21789
22484
|
const bunServer = Bun.serve({
|
|
21790
22485
|
port: options.port,
|
|
21791
22486
|
hostname: options.host,
|
|
@@ -21799,26 +22494,119 @@ function startApiServer(app, options) {
|
|
|
21799
22494
|
}
|
|
21800
22495
|
return timeRequest(request, options.timing, () => app.fetch(request));
|
|
21801
22496
|
},
|
|
21802
|
-
websocket: getElysiaWsHandler(app)
|
|
22497
|
+
websocket: getElysiaWsHandler(app, openSockets)
|
|
21803
22498
|
});
|
|
21804
22499
|
attachBunServer(app, bunServer);
|
|
21805
|
-
return
|
|
22500
|
+
return {
|
|
22501
|
+
bunServer,
|
|
22502
|
+
closeWebSockets: () => {
|
|
22503
|
+
for (const ws of [...openSockets]) {
|
|
22504
|
+
try {
|
|
22505
|
+
ws.close(SERVICE_RESTART_CLOSE_CODE, "Service Restart");
|
|
22506
|
+
} catch {}
|
|
22507
|
+
}
|
|
22508
|
+
openSockets.clear();
|
|
22509
|
+
}
|
|
22510
|
+
};
|
|
21806
22511
|
}
|
|
21807
|
-
function getElysiaWsHandler(app) {
|
|
22512
|
+
function getElysiaWsHandler(app, openSockets) {
|
|
21808
22513
|
const cfg = app.config;
|
|
21809
|
-
|
|
22514
|
+
const base = {
|
|
21810
22515
|
...elysiaWebSocket,
|
|
21811
|
-
...cfg?.websocket ?? {}
|
|
21812
|
-
|
|
22516
|
+
...cfg?.websocket ?? {}
|
|
22517
|
+
};
|
|
22518
|
+
return {
|
|
22519
|
+
...base,
|
|
22520
|
+
maxPayloadLength: MAX_WEBSOCKET_MESSAGE_BYTES,
|
|
22521
|
+
open(ws) {
|
|
22522
|
+
openSockets.add(ws);
|
|
22523
|
+
return base.open?.(ws);
|
|
22524
|
+
},
|
|
22525
|
+
close(ws, code, reason) {
|
|
22526
|
+
openSockets.delete(ws);
|
|
22527
|
+
return base.close?.(ws, code, reason);
|
|
22528
|
+
}
|
|
21813
22529
|
};
|
|
21814
22530
|
}
|
|
22531
|
+
function resolveStopTimeoutMs(timeoutMs, fallbackMs) {
|
|
22532
|
+
const resolved = timeoutMs ?? fallbackMs;
|
|
22533
|
+
if (!Number.isFinite(resolved) || resolved < 0) {
|
|
22534
|
+
throw new Error("[SixbServer] Stop timeout must be a non-negative finite number.");
|
|
22535
|
+
}
|
|
22536
|
+
return resolved;
|
|
22537
|
+
}
|
|
22538
|
+
|
|
22539
|
+
class StopDeadline {
|
|
22540
|
+
at;
|
|
22541
|
+
constructor(timeoutMs) {
|
|
22542
|
+
this.at = Date.now() + timeoutMs;
|
|
22543
|
+
}
|
|
22544
|
+
remainingMs() {
|
|
22545
|
+
return this.at - Date.now();
|
|
22546
|
+
}
|
|
22547
|
+
bringForward(timeoutMs) {
|
|
22548
|
+
this.at = Math.min(this.at, Date.now() + timeoutMs);
|
|
22549
|
+
}
|
|
22550
|
+
}
|
|
22551
|
+
async function drainBunServer(server, deadline, beforeWait) {
|
|
22552
|
+
if (deadline.remainingMs() <= 0) {
|
|
22553
|
+
try {
|
|
22554
|
+
await beforeWait();
|
|
22555
|
+
} finally {
|
|
22556
|
+
await server.stop(true);
|
|
22557
|
+
}
|
|
22558
|
+
return;
|
|
22559
|
+
}
|
|
22560
|
+
const draining = server.stop(false);
|
|
22561
|
+
try {
|
|
22562
|
+
await beforeWait();
|
|
22563
|
+
} catch (error) {
|
|
22564
|
+
await server.stop(true);
|
|
22565
|
+
await draining;
|
|
22566
|
+
throw error;
|
|
22567
|
+
}
|
|
22568
|
+
await waitUntilIdleOrTimeout(server, draining, deadline);
|
|
22569
|
+
await server.stop(true);
|
|
22570
|
+
await draining;
|
|
22571
|
+
}
|
|
22572
|
+
async function waitUntilIdleOrTimeout(server, draining, deadline) {
|
|
22573
|
+
let settled = false;
|
|
22574
|
+
draining.then(() => {
|
|
22575
|
+
settled = true;
|
|
22576
|
+
}, () => {
|
|
22577
|
+
settled = true;
|
|
22578
|
+
});
|
|
22579
|
+
while (!settled && (server.pendingRequests > 0 || server.pendingWebSockets > 0)) {
|
|
22580
|
+
const remaining = deadline.remainingMs();
|
|
22581
|
+
if (remaining <= 0)
|
|
22582
|
+
return;
|
|
22583
|
+
let timer;
|
|
22584
|
+
try {
|
|
22585
|
+
await Promise.race([
|
|
22586
|
+
draining,
|
|
22587
|
+
new Promise((resolve) => {
|
|
22588
|
+
timer = setTimeout(resolve, Math.min(remaining, 25));
|
|
22589
|
+
})
|
|
22590
|
+
]);
|
|
22591
|
+
} finally {
|
|
22592
|
+
if (timer !== undefined)
|
|
22593
|
+
clearTimeout(timer);
|
|
22594
|
+
}
|
|
22595
|
+
}
|
|
22596
|
+
}
|
|
21815
22597
|
function attachBunServer(app, bunServer) {
|
|
21816
22598
|
app.server = bunServer;
|
|
21817
22599
|
}
|
|
22600
|
+
async function stopElysiaHooks(app) {
|
|
22601
|
+
const internal = app;
|
|
22602
|
+
const hooks = internal.event?.stop ?? [];
|
|
22603
|
+
internal.server = null;
|
|
22604
|
+
await Promise.all(hooks.map((hook) => Promise.resolve(hook.fn(app))));
|
|
22605
|
+
}
|
|
21818
22606
|
export {
|
|
21819
22607
|
SixbServer,
|
|
21820
22608
|
createSixbServer,
|
|
21821
22609
|
requestTimingOptionsFromEnv
|
|
21822
22610
|
};
|
|
21823
22611
|
|
|
21824
|
-
//# debugId=
|
|
22612
|
+
//# debugId=FA111C44817B2F5664756E2164756E21
|