@sixb/server 0.1.20 → 0.1.21
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/artifacts/frame.d.ts +13 -0
- package/dist/artifacts/frame.d.ts.map +1 -0
- package/dist/auth/browser-origin.d.ts +5 -0
- package/dist/auth/browser-origin.d.ts.map +1 -1
- package/dist/auth/public-routes.d.ts.map +1 -1
- package/dist/files/content.d.ts +2 -3
- package/dist/files/content.d.ts.map +1 -1
- package/dist/index.js +3427 -2402
- package/dist/index.js.map +23 -17
- package/dist/openapi/tags.d.ts +10 -2
- package/dist/openapi/tags.d.ts.map +1 -1
- package/dist/registerRoutes.d.ts +3 -0
- package/dist/registerRoutes.d.ts.map +1 -1
- package/dist/routes/activity.d.ts +35 -0
- package/dist/routes/activity.d.ts.map +1 -0
- package/dist/routes/agents.d.ts +18 -27
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/artifact-frames.d.ts +98 -0
- package/dist/routes/artifact-frames.d.ts.map +1 -0
- package/dist/routes/artifacts.d.ts +852 -0
- package/dist/routes/artifacts.d.ts.map +1 -0
- package/dist/routes/auth.d.ts +1 -1
- package/dist/routes/connector-connection-runs.d.ts +59 -59
- package/dist/routes/connector-connections.d.ts +2 -2
- package/dist/routes/datasets.d.ts +7 -7
- package/dist/routes/events.d.ts +1 -1
- package/dist/routes/pipelines.d.ts +31 -31
- package/dist/routes/projections.d.ts +10 -10
- package/dist/routes/share-grants.d.ts +5 -5
- package/dist/routes/syncs.d.ts +38 -38
- package/dist/routes/workflows.d.ts +30 -30
- package/dist/routes/ws/events.d.ts.map +1 -1
- package/dist/routes/ws/subscription-hub.d.ts +8 -3
- package/dist/routes/ws/subscription-hub.d.ts.map +1 -1
- package/dist/schemas/activity.d.ts +1278 -0
- package/dist/schemas/activity.d.ts.map +1 -0
- package/dist/schemas/agents.d.ts +96 -144
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/ai-accounting.d.ts +24 -24
- package/dist/schemas/ai-limits.d.ts +26 -26
- package/dist/schemas/artifacts.d.ts +1305 -0
- package/dist/schemas/artifacts.d.ts.map +1 -0
- package/dist/schemas/auth.d.ts +6 -6
- package/dist/schemas/connectors.d.ts +30 -30
- package/dist/schemas/datasets.d.ts +10 -10
- package/dist/schemas/events.d.ts +6 -6
- package/dist/schemas/pipelines.d.ts +35 -35
- package/dist/schemas/projections.d.ts +40 -40
- package/dist/schemas/share-grants.d.ts +16 -16
- package/dist/schemas/syncs.d.ts +36 -36
- package/dist/schemas/workflows.d.ts +84 -84
- package/dist/server.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/artifacts/frame.ts +46 -0
- package/src/auth/browser-origin.ts +12 -2
- package/src/auth/public-routes.ts +10 -0
- package/src/files/content.ts +9 -13
- package/src/openapi/tags.ts +8 -0
- package/src/registerRoutes.ts +9 -0
- package/src/routes/activity.ts +327 -0
- package/src/routes/agents.ts +1 -1
- package/src/routes/artifact-frames.ts +138 -0
- package/src/routes/artifacts.ts +442 -0
- package/src/routes/file-downloads.ts +1 -3
- package/src/routes/ws/events.ts +3 -2
- package/src/routes/ws/subscription-hub.ts +53 -20
- package/src/schemas/activity.ts +285 -0
- package/src/schemas/agents.ts +1 -2
- package/src/schemas/artifacts.ts +158 -0
- package/src/server.ts +25 -9
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ACTIVITY_BATCH_LIMIT,
|
|
3
|
+
ACTIVITY_EVENT_ID_PATTERN,
|
|
4
|
+
ACTIVITY_HOSTNAME_PATTERN,
|
|
5
|
+
ACTIVITY_ID_MAX_LENGTH,
|
|
6
|
+
ACTIVITY_INTERACTION_NAME_MAX_LENGTH,
|
|
7
|
+
ACTIVITY_INTERACTION_NAME_PATTERN,
|
|
8
|
+
ACTIVITY_LABEL_MAX_LENGTH,
|
|
9
|
+
ACTIVITY_LABEL_PATTERN,
|
|
10
|
+
ACTIVITY_MAX_PAGE_SIZE,
|
|
11
|
+
ACTIVITY_MAX_PERIOD_MS,
|
|
12
|
+
ACTIVITY_REFERRER_MAX_LENGTH,
|
|
13
|
+
ACTIVITY_ROUTE_MAX_LENGTH,
|
|
14
|
+
ACTIVITY_VISIT_ID_PATTERN,
|
|
15
|
+
isActivityRoutePattern,
|
|
16
|
+
} from "@sixb/core/internal/storage"
|
|
17
|
+
import { z } from "zod"
|
|
18
|
+
import { ActionRunStatusSchema } from "./actions"
|
|
19
|
+
import { AgentRunStatusSchema } from "./agents"
|
|
20
|
+
import { AiCostSummarySchema } from "./ai-accounting"
|
|
21
|
+
import { WorkflowRunStatusSchema } from "./workflows"
|
|
22
|
+
|
|
23
|
+
// The limits come from the activity policy, so the API refuses what the providers would.
|
|
24
|
+
const VisitIdSchema = z.string().regex(ACTIVITY_VISIT_ID_PATTERN)
|
|
25
|
+
|
|
26
|
+
const UserIdSchema = z
|
|
27
|
+
.string()
|
|
28
|
+
.min(1)
|
|
29
|
+
.max(ACTIVITY_ID_MAX_LENGTH)
|
|
30
|
+
.refine((value) => value.trim().length > 0, "Expected a user id")
|
|
31
|
+
|
|
32
|
+
const RouteSchema = z
|
|
33
|
+
.string()
|
|
34
|
+
.min(1)
|
|
35
|
+
.max(ACTIVITY_ROUTE_MAX_LENGTH)
|
|
36
|
+
.startsWith("/")
|
|
37
|
+
.refine(isActivityRoutePattern, "Expected a normalized route pattern")
|
|
38
|
+
|
|
39
|
+
const LabelSchema = z
|
|
40
|
+
.string()
|
|
41
|
+
.min(1)
|
|
42
|
+
.max(ACTIVITY_LABEL_MAX_LENGTH)
|
|
43
|
+
.regex(ACTIVITY_LABEL_PATTERN)
|
|
44
|
+
.refine((value) => value === value.trim(), "Expected a trimmed label")
|
|
45
|
+
|
|
46
|
+
const ActivityAttributionSchema = z
|
|
47
|
+
.object({
|
|
48
|
+
source: LabelSchema.optional(),
|
|
49
|
+
medium: LabelSchema.optional(),
|
|
50
|
+
campaign: LabelSchema.optional(),
|
|
51
|
+
referrer: z
|
|
52
|
+
.string()
|
|
53
|
+
.min(1)
|
|
54
|
+
.max(ACTIVITY_REFERRER_MAX_LENGTH)
|
|
55
|
+
.regex(ACTIVITY_HOSTNAME_PATTERN)
|
|
56
|
+
.optional(),
|
|
57
|
+
})
|
|
58
|
+
.strict()
|
|
59
|
+
|
|
60
|
+
export const ActivityEventInputSchema = z.discriminatedUnion("type", [
|
|
61
|
+
z
|
|
62
|
+
.object({
|
|
63
|
+
id: z.string().regex(ACTIVITY_EVENT_ID_PATTERN),
|
|
64
|
+
type: z.enum(["page.view", "visit.activity"]),
|
|
65
|
+
route: RouteSchema,
|
|
66
|
+
attribution: ActivityAttributionSchema.optional(),
|
|
67
|
+
})
|
|
68
|
+
.strict(),
|
|
69
|
+
z
|
|
70
|
+
.object({
|
|
71
|
+
id: z.string().regex(ACTIVITY_EVENT_ID_PATTERN),
|
|
72
|
+
type: z.literal("ui.interaction"),
|
|
73
|
+
name: z
|
|
74
|
+
.string()
|
|
75
|
+
.min(1)
|
|
76
|
+
.max(ACTIVITY_INTERACTION_NAME_MAX_LENGTH)
|
|
77
|
+
.regex(ACTIVITY_INTERACTION_NAME_PATTERN),
|
|
78
|
+
route: RouteSchema,
|
|
79
|
+
})
|
|
80
|
+
.strict(),
|
|
81
|
+
])
|
|
82
|
+
|
|
83
|
+
export const CaptureActivityBodySchema = z
|
|
84
|
+
.object({ events: z.array(ActivityEventInputSchema).min(1).max(ACTIVITY_BATCH_LIMIT) })
|
|
85
|
+
.strict()
|
|
86
|
+
.refine(
|
|
87
|
+
(body) => new Set(body.events.map((event) => event.id)).size === body.events.length,
|
|
88
|
+
"Event ids must be unique"
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
export const ActivityCaptureOptionsSchema = z.object({
|
|
92
|
+
enabled: z.boolean(),
|
|
93
|
+
idleTimeoutMs: z.number(),
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
export const ActivityCaptureResultSchema = z.object({
|
|
97
|
+
status: z.enum(["accepted", "disabled", "throttled"]),
|
|
98
|
+
accepted: z.number(),
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
const ActivityActorSchema = z.discriminatedUnion("type", [
|
|
102
|
+
z.object({ type: z.literal("user"), userId: z.string() }),
|
|
103
|
+
z.object({
|
|
104
|
+
type: z.literal("share"),
|
|
105
|
+
grantId: z.string(),
|
|
106
|
+
definitionId: z.string().optional(),
|
|
107
|
+
}),
|
|
108
|
+
])
|
|
109
|
+
|
|
110
|
+
const ActivityVisitSchema = z.object({
|
|
111
|
+
id: VisitIdSchema,
|
|
112
|
+
actor: ActivityActorSchema,
|
|
113
|
+
attribution: ActivityAttributionSchema.nullable(),
|
|
114
|
+
startedAt: z.string().datetime(),
|
|
115
|
+
lastSeenAt: z.string().datetime(),
|
|
116
|
+
pageViews: z.number(),
|
|
117
|
+
interactions: z.number(),
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
export const ActivityVisitsPageSchema = z.object({
|
|
121
|
+
visits: z.array(ActivityVisitSchema),
|
|
122
|
+
hasMore: z.boolean(),
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
export const ActivityUsersPageSchema = z.object({
|
|
126
|
+
users: z.array(
|
|
127
|
+
z.object({
|
|
128
|
+
userId: z.string(),
|
|
129
|
+
displayName: z.string().optional(),
|
|
130
|
+
lastSeenAt: z.string().datetime(),
|
|
131
|
+
visits: z.number(),
|
|
132
|
+
pageViews: z.number(),
|
|
133
|
+
})
|
|
134
|
+
),
|
|
135
|
+
hasMore: z.boolean(),
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
export const ActivitySummarySchema = z.object({
|
|
139
|
+
users: z.number(),
|
|
140
|
+
visits: z.number(),
|
|
141
|
+
sharedVisits: z.number(),
|
|
142
|
+
pageViews: z.number(),
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
const ActivityConnectionStatusSchema = z.enum(["active", "expired", "revoked"])
|
|
146
|
+
|
|
147
|
+
const ActivitySessionConnectionSchema = z.object({
|
|
148
|
+
type: z.literal("session"),
|
|
149
|
+
device: z.object({ browser: z.string().optional(), os: z.string().optional() }),
|
|
150
|
+
clientName: z.string().optional(),
|
|
151
|
+
status: ActivityConnectionStatusSchema,
|
|
152
|
+
createdAt: z.string().datetime(),
|
|
153
|
+
lastSeenAt: z.string().datetime().optional(),
|
|
154
|
+
revokedAt: z.string().datetime().optional(),
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
const ActivityShareConnectionSchema = z.object({
|
|
158
|
+
type: z.literal("share"),
|
|
159
|
+
grantId: z.string(),
|
|
160
|
+
definitionId: z.string().optional(),
|
|
161
|
+
status: ActivityConnectionStatusSchema,
|
|
162
|
+
createdAt: z.string().datetime(),
|
|
163
|
+
revokedAt: z.string().datetime().optional(),
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
const ActivityTimelineEntrySchema = z.discriminatedUnion("kind", [
|
|
167
|
+
z.object({
|
|
168
|
+
kind: z.literal("page"),
|
|
169
|
+
at: z.string().datetime(),
|
|
170
|
+
sequence: z.number(),
|
|
171
|
+
route: z.string(),
|
|
172
|
+
}),
|
|
173
|
+
z.object({
|
|
174
|
+
kind: z.literal("interaction"),
|
|
175
|
+
at: z.string().datetime(),
|
|
176
|
+
sequence: z.number(),
|
|
177
|
+
name: z.string(),
|
|
178
|
+
route: z.string(),
|
|
179
|
+
}),
|
|
180
|
+
z.object({
|
|
181
|
+
kind: z.literal("action"),
|
|
182
|
+
at: z.string().datetime(),
|
|
183
|
+
executionId: z.string(),
|
|
184
|
+
actionId: z.string(),
|
|
185
|
+
runId: z.string(),
|
|
186
|
+
status: z.union([ActionRunStatusSchema, z.literal("incomplete")]),
|
|
187
|
+
runVisible: z.boolean().describe("Whether the viewer may read the run itself."),
|
|
188
|
+
object: z.object({ objectTypeId: z.string(), primaryId: z.string() }).optional(),
|
|
189
|
+
}),
|
|
190
|
+
z.object({
|
|
191
|
+
kind: z.literal("workflow"),
|
|
192
|
+
at: z.string().datetime(),
|
|
193
|
+
executionId: z.string(),
|
|
194
|
+
workflowId: z.string(),
|
|
195
|
+
runId: z.string(),
|
|
196
|
+
status: z.union([WorkflowRunStatusSchema, z.literal("incomplete")]),
|
|
197
|
+
runVisible: z.boolean().describe("Whether the viewer may read the run itself."),
|
|
198
|
+
}),
|
|
199
|
+
z.object({
|
|
200
|
+
kind: z.literal("agent"),
|
|
201
|
+
at: z.string().datetime(),
|
|
202
|
+
executionId: z.string(),
|
|
203
|
+
runId: z.string(),
|
|
204
|
+
threadId: z.string(),
|
|
205
|
+
status: AgentRunStatusSchema,
|
|
206
|
+
messages: z.number(),
|
|
207
|
+
cost: AiCostSummarySchema.optional(),
|
|
208
|
+
}),
|
|
209
|
+
])
|
|
210
|
+
|
|
211
|
+
export const ActivityVisitTimelineSchema = z.object({
|
|
212
|
+
visit: ActivityVisitSchema,
|
|
213
|
+
connection: z
|
|
214
|
+
.discriminatedUnion("type", [ActivitySessionConnectionSchema, ActivityShareConnectionSchema])
|
|
215
|
+
.optional(),
|
|
216
|
+
entries: z.array(ActivityTimelineEntrySchema),
|
|
217
|
+
truncated: z.boolean(),
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
export const ActivityConnectionsPageSchema = z.object({
|
|
221
|
+
connections: z.array(
|
|
222
|
+
ActivitySessionConnectionSchema.extend({
|
|
223
|
+
visits: z.number(),
|
|
224
|
+
latestVisits: z.array(ActivityVisitSchema),
|
|
225
|
+
})
|
|
226
|
+
),
|
|
227
|
+
nextCursor: z.string().optional(),
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
export const ActivityCalendarSchema = z.object({
|
|
231
|
+
userId: z.string(),
|
|
232
|
+
year: z.number(),
|
|
233
|
+
days: z.array(z.object({ day: z.string(), visits: z.number(), pageViews: z.number() })),
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
const periodFields = {
|
|
237
|
+
from: z.string().datetime(),
|
|
238
|
+
to: z.string().datetime(),
|
|
239
|
+
userId: UserIdSchema.optional(),
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const PageSizeSchema = z.coerce.number().int().min(1).max(ACTIVITY_MAX_PAGE_SIZE)
|
|
243
|
+
|
|
244
|
+
const pageFields = {
|
|
245
|
+
limit: PageSizeSchema.optional(),
|
|
246
|
+
beforeAt: z.string().datetime().optional(),
|
|
247
|
+
beforeId: z.string().min(1).max(ACTIVITY_ID_MAX_LENGTH).optional(),
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function isBoundedPeriod(input: { readonly from: string; readonly to: string }): boolean {
|
|
251
|
+
const span = Date.parse(input.to) - Date.parse(input.from)
|
|
252
|
+
return span > 0 && span <= ACTIVITY_MAX_PERIOD_MS
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function hasWholeCursor(input: { readonly beforeAt?: string; readonly beforeId?: string }) {
|
|
256
|
+
return (input.beforeAt === undefined) === (input.beforeId === undefined)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export const ActivityPeriodQuerySchema = z
|
|
260
|
+
.object(periodFields)
|
|
261
|
+
.refine(isBoundedPeriod, "Expected an ordered period of at most 31 days")
|
|
262
|
+
|
|
263
|
+
export const ActivityPageQuerySchema = z
|
|
264
|
+
.object({ ...periodFields, ...pageFields })
|
|
265
|
+
.refine(isBoundedPeriod, "Expected an ordered period of at most 31 days")
|
|
266
|
+
.refine(hasWholeCursor, "beforeAt and beforeId go together")
|
|
267
|
+
|
|
268
|
+
export const ActivityCalendarQuerySchema = z.object({
|
|
269
|
+
userId: UserIdSchema,
|
|
270
|
+
year: z.coerce.number().int().min(1970).max(9998),
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
export const ActivityConnectionsQuerySchema = z.object({
|
|
274
|
+
userId: UserIdSchema,
|
|
275
|
+
limit: PageSizeSchema.optional(),
|
|
276
|
+
cursor: z
|
|
277
|
+
.string()
|
|
278
|
+
.min(1)
|
|
279
|
+
.max(200)
|
|
280
|
+
.regex(/^[A-Za-z0-9_-]+$/)
|
|
281
|
+
.optional()
|
|
282
|
+
.describe("The previous page's nextCursor."),
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
export const ActivityVisitParamsSchema = z.object({ visitId: VisitIdSchema })
|
package/src/schemas/agents.ts
CHANGED
|
@@ -202,8 +202,7 @@ export const AgentMessagePartSchema = z.union([
|
|
|
202
202
|
export const AgentRunDiagnosticSchema = z.object({
|
|
203
203
|
code: z.enum(AGENT_RUN_DIAGNOSTIC_CODES),
|
|
204
204
|
severity: z.enum(["warning", "error"]),
|
|
205
|
-
scope: z.enum(["
|
|
206
|
-
path: z.string().optional(),
|
|
205
|
+
scope: z.enum(["run"]),
|
|
207
206
|
message: z.string(),
|
|
208
207
|
})
|
|
209
208
|
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { ARTIFACT_KINDS } from "@sixb/core/artifacts"
|
|
2
|
+
import { z } from "zod"
|
|
3
|
+
import { ErrorResponseSchema, PrincipalSchema } from "./common"
|
|
4
|
+
import { FileRefSchema } from "./files"
|
|
5
|
+
|
|
6
|
+
const ArtifactKindSchema = z.enum(ARTIFACT_KINDS)
|
|
7
|
+
|
|
8
|
+
const ArtifactFileSchema = z.object({
|
|
9
|
+
path: z
|
|
10
|
+
.string()
|
|
11
|
+
.min(1)
|
|
12
|
+
.describe("The file's path inside the artifact, such as figures/revenue.svg"),
|
|
13
|
+
file: FileRefSchema,
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const DocumentOutlineSchema = z.object({
|
|
17
|
+
kind: z.literal("document"),
|
|
18
|
+
headings: z.array(z.object({ depth: z.number().int(), text: z.string(), slug: z.string() })),
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const SheetOutlineSchema = z.object({
|
|
22
|
+
kind: z.literal("sheet"),
|
|
23
|
+
sheets: z.array(
|
|
24
|
+
z.object({ name: z.string(), rows: z.number().int(), columns: z.array(z.string()) })
|
|
25
|
+
),
|
|
26
|
+
charts: z.array(z.string()),
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const SlidesOutlineSchema = z.object({
|
|
30
|
+
kind: z.literal("slides"),
|
|
31
|
+
slides: z.array(z.object({ title: z.string().optional() })),
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const FileOutlineSchema = z.object({ kind: z.literal("file"), mediaType: z.string() })
|
|
35
|
+
|
|
36
|
+
const ArtifactOutlineSchema = z.discriminatedUnion("kind", [
|
|
37
|
+
DocumentOutlineSchema,
|
|
38
|
+
SheetOutlineSchema,
|
|
39
|
+
SlidesOutlineSchema,
|
|
40
|
+
FileOutlineSchema,
|
|
41
|
+
])
|
|
42
|
+
|
|
43
|
+
const ArtifactReferenceSchema = z.object({
|
|
44
|
+
address: z.string(),
|
|
45
|
+
as: z.enum(["embed", "link"]),
|
|
46
|
+
at: z.string(),
|
|
47
|
+
resolvedVersion: z.number().int().positive(),
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const ArtifactWarningSchema = z.object({
|
|
51
|
+
code: z.string(),
|
|
52
|
+
message: z.string(),
|
|
53
|
+
part: z.string().optional(),
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const ArtifactSchema = z.object({
|
|
57
|
+
id: z.string(),
|
|
58
|
+
projectId: z.string(),
|
|
59
|
+
kind: ArtifactKindSchema,
|
|
60
|
+
title: z.string(),
|
|
61
|
+
owner: PrincipalSchema,
|
|
62
|
+
latestVersion: z.number().int().positive(),
|
|
63
|
+
createdAt: z.string(),
|
|
64
|
+
updatedAt: z.string(),
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
const ArtifactOriginSchema = z.object({ threadId: z.string(), runId: z.string() })
|
|
68
|
+
|
|
69
|
+
export const ArtifactVersionSchema = z.object({
|
|
70
|
+
artifactId: z.string(),
|
|
71
|
+
version: z.number().int().positive(),
|
|
72
|
+
title: z.string(),
|
|
73
|
+
entry: z.string(),
|
|
74
|
+
files: z.array(ArtifactFileSchema),
|
|
75
|
+
outline: ArtifactOutlineSchema,
|
|
76
|
+
references: z.array(ArtifactReferenceSchema),
|
|
77
|
+
author: PrincipalSchema,
|
|
78
|
+
origin: ArtifactOriginSchema.optional(),
|
|
79
|
+
createdAt: z.string(),
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
const ArtifactVersionSummarySchema = ArtifactVersionSchema.pick({
|
|
83
|
+
version: true,
|
|
84
|
+
title: true,
|
|
85
|
+
author: true,
|
|
86
|
+
origin: true,
|
|
87
|
+
createdAt: true,
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
export const ArtifactParamsSchema = z.object({ artifactId: z.string().min(1) })
|
|
91
|
+
|
|
92
|
+
export const ArtifactVersionParamsSchema = ArtifactParamsSchema.extend({
|
|
93
|
+
version: z
|
|
94
|
+
.string()
|
|
95
|
+
.regex(/^(?:latest|[1-9]\d*)$/)
|
|
96
|
+
.describe('A version number, or "latest"'),
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
export const ArtifactListQuerySchema = z
|
|
100
|
+
.object({
|
|
101
|
+
thread: z
|
|
102
|
+
.string()
|
|
103
|
+
.min(1)
|
|
104
|
+
.optional()
|
|
105
|
+
.describe("Only artifacts with a version the Agent published in this thread"),
|
|
106
|
+
kind: ArtifactKindSchema.optional().describe("Only artifacts of this kind"),
|
|
107
|
+
limit: z.string().optional(),
|
|
108
|
+
offset: z.string().optional(),
|
|
109
|
+
})
|
|
110
|
+
.strict()
|
|
111
|
+
|
|
112
|
+
export const ArtifactListResponseSchema = z.object({
|
|
113
|
+
artifacts: z.array(ArtifactSchema),
|
|
114
|
+
hasMore: z.boolean(),
|
|
115
|
+
total: z.number().int(),
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
export const ArtifactResponseSchema = z.object({
|
|
119
|
+
artifact: ArtifactSchema,
|
|
120
|
+
versions: z.array(ArtifactVersionSummarySchema).describe("Newest first"),
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
export const PublishArtifactBodySchema = z
|
|
124
|
+
.object({
|
|
125
|
+
kind: ArtifactKindSchema,
|
|
126
|
+
title: z.string(),
|
|
127
|
+
files: z
|
|
128
|
+
.array(ArtifactFileSchema)
|
|
129
|
+
.min(1)
|
|
130
|
+
.describe("Files stored with POST /api/files, at their paths in the artifact"),
|
|
131
|
+
})
|
|
132
|
+
.strict()
|
|
133
|
+
|
|
134
|
+
export const PublishedArtifactResponseSchema = z.object({
|
|
135
|
+
artifact: ArtifactSchema,
|
|
136
|
+
version: ArtifactVersionSchema,
|
|
137
|
+
warnings: z.array(ArtifactWarningSchema),
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
export const DeleteArtifactResponseSchema = z.object({ deleted: z.literal(true) })
|
|
141
|
+
|
|
142
|
+
export const ArtifactFrameResponseSchema = z.object({
|
|
143
|
+
path: z
|
|
144
|
+
.string()
|
|
145
|
+
.describe(
|
|
146
|
+
"The frame's base path on this API, ending in /; the deck's entry is served under it"
|
|
147
|
+
),
|
|
148
|
+
expiresAt: z.string().describe("When the frame stops serving; ask for a new one before then"),
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
export const ArtifactErrorResponseSchema = ErrorResponseSchema.extend({
|
|
152
|
+
code: z
|
|
153
|
+
.string()
|
|
154
|
+
.optional()
|
|
155
|
+
.describe(
|
|
156
|
+
"Stable machine-readable failure code: artifact_not_found, artifact_kind_mismatch, invalid_artifact, not_allowed, or storage_unavailable."
|
|
157
|
+
),
|
|
158
|
+
})
|
package/src/server.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { cors } from "@elysiajs/cors"
|
|
2
2
|
import { openapi } from "@elysiajs/openapi"
|
|
3
3
|
import type { OntologyMaintenanceHandle, SixbHostView } from "@sixb/core"
|
|
4
|
+
import { ARTIFACT_FRAME_ROUTE_PREFIX } from "@sixb/core/internal/artifacts/frames"
|
|
4
5
|
import { CSRF_HEADER_NAME, setRequestClientAddress } from "@sixb/core/internal/auth"
|
|
5
6
|
import { bindRequestExecution } from "@sixb/core/internal/request-execution"
|
|
6
7
|
import { setApiPublicOrigin } from "@sixb/core/internal/runtime"
|
|
8
|
+
import { checkPipelineMarkings, warmAppliedMarkings } from "@sixb/core/internal/security"
|
|
7
9
|
import type { Server } from "bun"
|
|
8
10
|
import { Elysia, ParseError } from "elysia"
|
|
9
11
|
import { websocket as elysiaWebSocket } from "elysia/ws"
|
|
@@ -11,7 +13,6 @@ import { zodToJsonSchema } from "zod-to-json-schema"
|
|
|
11
13
|
import {
|
|
12
14
|
type AuthInvitationRedirectContext,
|
|
13
15
|
type AuthInvitationRedirectInput,
|
|
14
|
-
BrowserOriginError,
|
|
15
16
|
createApiBrowserAuthContextResolver,
|
|
16
17
|
createApiBrowserAuthRedirectContextResolver,
|
|
17
18
|
isAllowedApiBrowserOrigin,
|
|
@@ -168,6 +169,16 @@ export class SixbServer {
|
|
|
168
169
|
throw new Error("[SixbServer] Server is already running.")
|
|
169
170
|
}
|
|
170
171
|
|
|
172
|
+
// Startup cannot see through SQL steps: check what they derive before serving any request.
|
|
173
|
+
await checkPipelineMarkings({
|
|
174
|
+
definitions: this.hostRuntime.definitions,
|
|
175
|
+
lakeStorage: this.hostRuntime.lakeStorage,
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
// Objects keep the markings of the versions they were projected from. The first read that
|
|
179
|
+
// needs them waits for them; reading them now spares that read the wait.
|
|
180
|
+
warmAppliedMarkings(this.hostRuntime)
|
|
181
|
+
|
|
171
182
|
const maintenance = await this.hostRuntime.startOntologyMaintenance()
|
|
172
183
|
this.maintenance = maintenance
|
|
173
184
|
|
|
@@ -442,6 +453,7 @@ export function createSixbApi(server: SixbServer) {
|
|
|
442
453
|
})
|
|
443
454
|
registerHttpRoutes(app, host, {
|
|
444
455
|
sharedAccess,
|
|
456
|
+
browserPolicy: apiBrowserPolicy,
|
|
445
457
|
connectorConnections: {
|
|
446
458
|
resolveReturnTo: (request, returnTo) =>
|
|
447
459
|
server.resolveAuthRedirectContext(request, { returnTo }).returnTo,
|
|
@@ -499,14 +511,18 @@ function rejectDisallowedBrowserOrigin(
|
|
|
499
511
|
return undefined
|
|
500
512
|
}
|
|
501
513
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
514
|
+
// A frame's page has an opaque origin, so what it loads arrives with `Origin: null`. Its token
|
|
515
|
+
// is the credential and no cookie counts there, so frames are the one place that is allowed, and
|
|
516
|
+
// only to read, as `classifyRoute` makes them public.
|
|
517
|
+
if (
|
|
518
|
+
(request.method === "GET" || request.method === "HEAD") &&
|
|
519
|
+
new URL(request.url).pathname.startsWith(ARTIFACT_FRAME_ROUTE_PREFIX)
|
|
520
|
+
) {
|
|
521
|
+
return undefined
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
if (isAllowedApiBrowserOrigin(policy, request)) {
|
|
525
|
+
return undefined
|
|
510
526
|
}
|
|
511
527
|
|
|
512
528
|
return new Response(JSON.stringify({ error: "Browser origin is not allowed" }), {
|