@sixb/server 0.1.25 → 0.2.0
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/README.md +1 -1
- package/dist/auth/public-routes.d.ts.map +1 -1
- package/dist/auth/run-token.d.ts +28 -0
- package/dist/auth/run-token.d.ts.map +1 -0
- package/dist/auth/scope.d.ts +11 -13
- package/dist/auth/scope.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4999 -4151
- package/dist/index.js.map +47 -43
- package/dist/registerRoutes.d.ts.map +1 -1
- package/dist/routes/actions.d.ts +1 -1
- package/dist/routes/agent-approval-gate.d.ts +7 -4
- package/dist/routes/agent-approval-gate.d.ts.map +1 -1
- package/dist/routes/agent-approvals.d.ts +14 -5
- package/dist/routes/agent-approvals.d.ts.map +1 -1
- package/dist/routes/agent-children.d.ts +2 -2
- package/dist/routes/agent-computers.d.ts +338 -0
- package/dist/routes/agent-computers.d.ts.map +1 -0
- package/dist/routes/agent-runners.d.ts +74 -0
- package/dist/routes/agent-runners.d.ts.map +1 -0
- package/dist/routes/agents.d.ts +250 -16
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/ai-accounting.d.ts.map +1 -1
- package/dist/routes/artifacts.d.ts +5 -28
- package/dist/routes/artifacts.d.ts.map +1 -1
- package/dist/routes/auth.d.ts +10 -1
- package/dist/routes/auth.d.ts.map +1 -1
- package/dist/routes/datasets.d.ts +93 -17
- package/dist/routes/datasets.d.ts.map +1 -1
- package/dist/routes/events.d.ts +1 -1
- package/dist/routes/links.d.ts +121 -81
- package/dist/routes/links.d.ts.map +1 -1
- package/dist/routes/logs.d.ts +3 -3
- package/dist/routes/objects.d.ts +149 -58
- package/dist/routes/objects.d.ts.map +1 -1
- package/dist/routes/observed-agent-threads.d.ts +25 -4
- package/dist/routes/observed-agent-threads.d.ts.map +1 -1
- package/dist/routes/pipelines.d.ts +2 -2
- package/dist/routes/pipelines.d.ts.map +1 -1
- package/dist/routes/projections.d.ts +124 -122
- package/dist/routes/projections.d.ts.map +1 -1
- package/dist/routes/rules.d.ts +2 -2
- package/dist/routes/shared-access.d.ts +2 -2
- package/dist/routes/syncs.d.ts +34 -34
- package/dist/routes/syncs.d.ts.map +1 -1
- package/dist/routes/telemetry.d.ts +0 -50
- package/dist/routes/telemetry.d.ts.map +1 -1
- package/dist/routes/users.d.ts +1 -0
- package/dist/routes/users.d.ts.map +1 -1
- package/dist/routes/webhook-runs.d.ts +1 -1
- package/dist/routes/workflows.d.ts +25 -14
- package/dist/routes/workflows.d.ts.map +1 -1
- package/dist/routes/ws/agents.d.ts +4 -1
- package/dist/routes/ws/agents.d.ts.map +1 -1
- package/dist/routes/ws/logs.d.ts +10 -10
- package/dist/schemas/actions.d.ts +3 -3
- package/dist/schemas/activity.d.ts +4 -4
- package/dist/schemas/agent-approvals.d.ts +21 -21
- package/dist/schemas/agents.d.ts +819 -88
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/ai-accounting.d.ts +1114 -6
- package/dist/schemas/ai-accounting.d.ts.map +1 -1
- package/dist/schemas/auth.d.ts +49 -2
- package/dist/schemas/auth.d.ts.map +1 -1
- package/dist/schemas/datasets.d.ts +303 -60
- package/dist/schemas/datasets.d.ts.map +1 -1
- package/dist/schemas/event-payloads.d.ts +6 -6
- package/dist/schemas/events.d.ts +8 -8
- package/dist/schemas/lineage.d.ts +1272 -0
- package/dist/schemas/lineage.d.ts.map +1 -0
- package/dist/schemas/links.d.ts +4 -27
- package/dist/schemas/links.d.ts.map +1 -1
- package/dist/schemas/logs.d.ts +22 -22
- package/dist/schemas/objects.d.ts +7 -26
- package/dist/schemas/objects.d.ts.map +1 -1
- package/dist/schemas/pipelines.d.ts +12 -12
- package/dist/schemas/projections.d.ts +747 -733
- package/dist/schemas/projections.d.ts.map +1 -1
- package/dist/schemas/rules.d.ts +4 -4
- package/dist/schemas/shared-access.d.ts +2 -2
- package/dist/schemas/syncs.d.ts +24 -24
- package/dist/schemas/telemetry.d.ts +0 -13
- package/dist/schemas/telemetry.d.ts.map +1 -1
- package/dist/schemas/users.d.ts +8 -0
- package/dist/schemas/users.d.ts.map +1 -1
- package/dist/schemas/webhook-runs.d.ts +2 -2
- package/dist/schemas/workflows.d.ts +133 -44
- package/dist/schemas/workflows.d.ts.map +1 -1
- package/dist/server.d.ts +5 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/utils/request-body.d.ts +5 -0
- package/dist/utils/request-body.d.ts.map +1 -1
- package/dist/utils/request-timing.d.ts +18 -0
- package/dist/utils/request-timing.d.ts.map +1 -0
- package/package.json +7 -7
- package/src/auth/public-routes.ts +0 -6
- package/src/auth/run-token.ts +327 -0
- package/src/auth/scope.ts +16 -37
- package/src/index.ts +1 -0
- package/src/registerRoutes.ts +4 -2
- package/src/routes/agent-approval-gate.ts +40 -14
- package/src/routes/agent-approvals.ts +3 -3
- package/src/routes/agent-computers.ts +348 -0
- package/src/routes/agent-runners.ts +205 -0
- package/src/routes/agents.ts +193 -26
- package/src/routes/ai-accounting.ts +149 -12
- package/src/routes/artifacts.ts +55 -11
- package/src/routes/auth.ts +24 -2
- package/src/routes/datasets.ts +60 -5
- package/src/routes/links.ts +43 -76
- package/src/routes/objects.ts +49 -42
- package/src/routes/observed-agent-threads.ts +2 -2
- package/src/routes/pipelines.ts +5 -0
- package/src/routes/syncs.ts +4 -0
- package/src/routes/telemetry.ts +1 -42
- package/src/routes/users.ts +15 -2
- package/src/routes/ws/agents.ts +10 -1
- package/src/schemas/agents.ts +131 -1
- package/src/schemas/ai-accounting.ts +78 -15
- package/src/schemas/artifacts.ts +1 -1
- package/src/schemas/auth.ts +19 -0
- package/src/schemas/datasets.ts +36 -0
- package/src/schemas/lineage.ts +115 -0
- package/src/schemas/links.ts +3 -11
- package/src/schemas/objects.ts +6 -10
- package/src/schemas/projections.ts +2 -0
- package/src/schemas/telemetry.ts +0 -6
- package/src/schemas/users.ts +6 -0
- package/src/server.ts +53 -15
- package/src/utils/request-body.ts +10 -4
- package/src/utils/request-timing.ts +136 -0
- package/dist/routes/agent-api-gateway.d.ts +0 -4
- package/dist/routes/agent-api-gateway.d.ts.map +0 -1
- package/src/routes/agent-api-gateway.ts +0 -404
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { SixbHostView } from "@sixb/core"
|
|
1
|
+
import type { AgentMessagePart, SixbHostView } from "@sixb/core"
|
|
2
2
|
import type {
|
|
3
3
|
AiAccountingAggregate,
|
|
4
|
+
AiAccountingFilters,
|
|
4
5
|
AiAccountingOverview,
|
|
6
|
+
AiAccountingRequester,
|
|
5
7
|
AiLimitPolicy,
|
|
6
8
|
AiLimitPolicyStatus,
|
|
7
9
|
AiModelCallAccountingItem,
|
|
@@ -45,7 +47,78 @@ function serializeAggregate(aggregate: AiAccountingAggregate) {
|
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
|
|
50
|
+
/** The person, source and kind filters a query names, as the storage reads them. */
|
|
51
|
+
function accountingFilters(parsed: {
|
|
52
|
+
readonly person?: string
|
|
53
|
+
readonly source?: string
|
|
54
|
+
readonly kind?: AiAccountingFilters["modelKind"]
|
|
55
|
+
}): Partial<Pick<AiAccountingFilters, "requester" | "source" | "modelKind">> {
|
|
56
|
+
const colon = parsed.person?.indexOf(":") ?? -1
|
|
57
|
+
return {
|
|
58
|
+
...(parsed.person === undefined
|
|
59
|
+
? {}
|
|
60
|
+
: {
|
|
61
|
+
requester:
|
|
62
|
+
parsed.person === "none"
|
|
63
|
+
? ("none" as const)
|
|
64
|
+
: {
|
|
65
|
+
type: parsed.person.slice(0, colon) as AiAccountingRequester["type"],
|
|
66
|
+
id: parsed.person.slice(colon + 1),
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
...(parsed.source === undefined
|
|
70
|
+
? {}
|
|
71
|
+
: {
|
|
72
|
+
source: parsed.source.startsWith("workflow:")
|
|
73
|
+
? { kind: "workflow" as const, workflowId: parsed.source.slice("workflow:".length) }
|
|
74
|
+
: { kind: parsed.source as "agent" | "action" | "workflow" | "other" },
|
|
75
|
+
}),
|
|
76
|
+
...(parsed.kind === undefined ? {} : { modelKind: parsed.kind }),
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
type RequesterDetails = ReadonlyMap<string, { readonly name?: string; readonly email?: string }>
|
|
81
|
+
|
|
82
|
+
const requesterKey = (requester: AiAccountingRequester) => `${requester.type}:${requester.id}`
|
|
83
|
+
|
|
84
|
+
/** Each requester's name and email, read once for the page they are on. */
|
|
85
|
+
async function requesterDetails(
|
|
86
|
+
host: SixbHostView,
|
|
87
|
+
requesters: readonly (AiAccountingRequester | undefined)[]
|
|
88
|
+
): Promise<RequesterDetails> {
|
|
89
|
+
const auth = host.storage.auth
|
|
90
|
+
const details = new Map<string, { name?: string; email?: string }>()
|
|
91
|
+
if (!auth) return details
|
|
92
|
+
const unique = [
|
|
93
|
+
...new Map(
|
|
94
|
+
requesters.flatMap((requester) => (requester ? [[requesterKey(requester), requester]] : []))
|
|
95
|
+
).values(),
|
|
96
|
+
]
|
|
97
|
+
const userIds = unique.flatMap((requester) => (requester.type === "user" ? [requester.id] : []))
|
|
98
|
+
if (userIds.length > 0) {
|
|
99
|
+
for (const user of await auth.users.getByIds({ projectId: host.id, ids: userIds })) {
|
|
100
|
+
details.set(`user:${user.id}`, {
|
|
101
|
+
...(user.displayName ? { name: user.displayName } : {}),
|
|
102
|
+
email: user.email,
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
for (const requester of unique) {
|
|
107
|
+
if (requester.type !== "serviceAccount") continue
|
|
108
|
+
const account = await auth.serviceAccounts.getById({ projectId: host.id, id: requester.id })
|
|
109
|
+
if (account) details.set(requesterKey(requester), { name: account.name })
|
|
110
|
+
}
|
|
111
|
+
return details
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function serializeRequester(
|
|
115
|
+
requester: AiAccountingRequester | undefined,
|
|
116
|
+
details: RequesterDetails
|
|
117
|
+
) {
|
|
118
|
+
return requester ? { ...requester, ...details.get(requesterKey(requester)) } : undefined
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function serializeOverview(overview: AiAccountingOverview, details: RequesterDetails) {
|
|
49
122
|
return AiAccountingOverviewResponseSchema.parse({
|
|
50
123
|
range: {
|
|
51
124
|
from: overview.range.from.toISOString(),
|
|
@@ -58,11 +131,24 @@ function serializeOverview(overview: AiAccountingOverview) {
|
|
|
58
131
|
end: period.end.toISOString(),
|
|
59
132
|
...serializeAggregate(period),
|
|
60
133
|
})),
|
|
134
|
+
modelSeries: overview.modelSeries.map((model) => ({
|
|
135
|
+
providerId: model.providerId,
|
|
136
|
+
modelId: model.modelId,
|
|
137
|
+
series: model.series.map((period) => ({
|
|
138
|
+
start: period.start.toISOString(),
|
|
139
|
+
end: period.end.toISOString(),
|
|
140
|
+
...serializeAggregate(period),
|
|
141
|
+
})),
|
|
142
|
+
})),
|
|
61
143
|
models: overview.models.map((model) => ({
|
|
62
144
|
providerId: model.providerId,
|
|
63
145
|
modelId: model.modelId,
|
|
64
146
|
...serializeAggregate(model),
|
|
65
147
|
})),
|
|
148
|
+
people: overview.people.map((person) => ({
|
|
149
|
+
...(person.requester ? { requester: serializeRequester(person.requester, details) } : {}),
|
|
150
|
+
...serializeAggregate(person),
|
|
151
|
+
})),
|
|
66
152
|
kinds: overview.kinds.map((kind) => ({
|
|
67
153
|
...(kind.modelKind === undefined ? {} : { modelKind: kind.modelKind }),
|
|
68
154
|
...serializeAggregate(kind),
|
|
@@ -173,29 +259,54 @@ function handleAiLimitRouteError(error: unknown, set: { status?: number | string
|
|
|
173
259
|
async function serializeGroup(
|
|
174
260
|
group: AiModelCallGroup,
|
|
175
261
|
host: SixbHostView,
|
|
176
|
-
sixb: RequestAuthState["sixb"]
|
|
262
|
+
sixb: RequestAuthState["sixb"],
|
|
263
|
+
details: RequesterDetails
|
|
177
264
|
) {
|
|
178
265
|
// Accounting is project-wide; conversation titles and delegation keys remain private.
|
|
179
266
|
const thread =
|
|
180
267
|
group.attribution?.kind === "agent" && sixb
|
|
181
268
|
? await sixb.agent.threads.getById(group.attribution.threadId)
|
|
182
269
|
: null
|
|
183
|
-
|
|
270
|
+
// The conversation's turns and sub-agents, read together, for the sub-agents' names and what
|
|
271
|
+
// each turn was asked.
|
|
272
|
+
const agents = host.storage.agents
|
|
273
|
+
const runIds = thread
|
|
184
274
|
? group.executions.flatMap((execution) =>
|
|
185
|
-
execution.attribution?.kind === "
|
|
275
|
+
execution.attribution?.kind === "agent"
|
|
276
|
+
? [execution.attribution.agentRunId]
|
|
277
|
+
: execution.attribution?.kind === "subagent"
|
|
278
|
+
? [execution.attribution.subagentRunId]
|
|
279
|
+
: []
|
|
186
280
|
)
|
|
187
281
|
: []
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
?
|
|
282
|
+
const runs =
|
|
283
|
+
agents && runIds.length > 0
|
|
284
|
+
? await agents.runs.getByIds({ projectId: host.id, ids: runIds })
|
|
191
285
|
: []
|
|
192
286
|
const labels = new Map(
|
|
193
|
-
|
|
287
|
+
runs.flatMap((run) =>
|
|
194
288
|
run.kind === "subagent" ? [[run.executionId, run.spawnKey] as const] : []
|
|
195
289
|
)
|
|
196
290
|
)
|
|
291
|
+
const prompts = new Map(
|
|
292
|
+
agents
|
|
293
|
+
? await Promise.all(
|
|
294
|
+
runs.flatMap((run) =>
|
|
295
|
+
run.kind === "conversation"
|
|
296
|
+
? [
|
|
297
|
+
agents.messages
|
|
298
|
+
.getById({ projectId: host.id, id: run.triggerMessageId })
|
|
299
|
+
.then((message) => [run.executionId, message && promptOf(message)] as const),
|
|
300
|
+
]
|
|
301
|
+
: []
|
|
302
|
+
)
|
|
303
|
+
)
|
|
304
|
+
: []
|
|
305
|
+
)
|
|
306
|
+
const { requester, ...rest } = group
|
|
197
307
|
return {
|
|
198
|
-
...
|
|
308
|
+
...rest,
|
|
309
|
+
...(requester ? { requester: serializeRequester(requester, details) } : {}),
|
|
199
310
|
label: thread?.title,
|
|
200
311
|
canOpenThread: thread !== null,
|
|
201
312
|
firstCallAt: group.firstCallAt.toISOString(),
|
|
@@ -203,12 +314,24 @@ async function serializeGroup(
|
|
|
203
314
|
executions: group.executions.map((execution) => ({
|
|
204
315
|
...execution,
|
|
205
316
|
label: labels.get(execution.executionId),
|
|
317
|
+
prompt: prompts.get(execution.executionId) ?? undefined,
|
|
206
318
|
firstCallAt: execution.firstCallAt.toISOString(),
|
|
207
319
|
lastCallAt: execution.lastCallAt.toISOString(),
|
|
208
320
|
})),
|
|
209
321
|
}
|
|
210
322
|
}
|
|
211
323
|
|
|
324
|
+
/** The opening of the message that started a turn, on one line. */
|
|
325
|
+
function promptOf(message: { readonly parts: readonly AgentMessagePart[] }): string | undefined {
|
|
326
|
+
const text = message.parts
|
|
327
|
+
.flatMap((part) => (part.type === "text" ? [part.text] : []))
|
|
328
|
+
.join(" ")
|
|
329
|
+
.replace(/\s+/g, " ")
|
|
330
|
+
.trim()
|
|
331
|
+
if (!text) return undefined
|
|
332
|
+
return text.length > 160 ? `${text.slice(0, 159)}…` : text
|
|
333
|
+
}
|
|
334
|
+
|
|
212
335
|
export function registerAiAccountingRoutes(app: Elysia, host: SixbHostView) {
|
|
213
336
|
app.get(
|
|
214
337
|
"/api/ai/accounting/overview",
|
|
@@ -227,8 +350,13 @@ export function registerAiAccountingRoutes(app: Elysia, host: SixbHostView) {
|
|
|
227
350
|
bucket: parsed.bucket,
|
|
228
351
|
providerId: parsed.providerId,
|
|
229
352
|
modelId: parsed.modelId,
|
|
353
|
+
...accountingFilters(parsed),
|
|
230
354
|
})
|
|
231
|
-
|
|
355
|
+
const details = await requesterDetails(
|
|
356
|
+
host,
|
|
357
|
+
overview.people.map((person) => person.requester)
|
|
358
|
+
)
|
|
359
|
+
return serializeOverview(overview, details)
|
|
232
360
|
} catch (error) {
|
|
233
361
|
return handleRouteError(error, set)
|
|
234
362
|
}
|
|
@@ -266,6 +394,7 @@ export function registerAiAccountingRoutes(app: Elysia, host: SixbHostView) {
|
|
|
266
394
|
to: new Date(parsed.to),
|
|
267
395
|
providerId: parsed.providerId,
|
|
268
396
|
modelId: parsed.modelId,
|
|
397
|
+
...accountingFilters(parsed),
|
|
269
398
|
executionId: parsed.executionId,
|
|
270
399
|
valuationStatus: parsed.valuationStatus,
|
|
271
400
|
limit: parseOptionalInt(parsed.limit),
|
|
@@ -530,13 +659,21 @@ export function registerAiAccountingRoutes(app: Elysia, host: SixbHostView) {
|
|
|
530
659
|
to: new Date(parsed.to),
|
|
531
660
|
providerId: parsed.providerId,
|
|
532
661
|
modelId: parsed.modelId,
|
|
662
|
+
...accountingFilters(parsed),
|
|
533
663
|
valuationStatus: parsed.valuationStatus,
|
|
664
|
+
sort: parsed.sort,
|
|
534
665
|
limit: parseOptionalInt(parsed.limit),
|
|
535
666
|
offset: parseOptionalInt(parsed.offset),
|
|
536
667
|
})
|
|
668
|
+
const details = await requesterDetails(
|
|
669
|
+
host,
|
|
670
|
+
result.items.map((group) => group.requester)
|
|
671
|
+
)
|
|
537
672
|
return AiModelCallGroupsResponseSchema.parse({
|
|
538
673
|
...result,
|
|
539
|
-
items: await Promise.all(
|
|
674
|
+
items: await Promise.all(
|
|
675
|
+
result.items.map((group) => serializeGroup(group, host, sixb, details))
|
|
676
|
+
),
|
|
540
677
|
})
|
|
541
678
|
} catch (error) {
|
|
542
679
|
return handleRouteError(error, set)
|
package/src/routes/artifacts.ts
CHANGED
|
@@ -8,6 +8,11 @@ import {
|
|
|
8
8
|
type PublishedArtifact,
|
|
9
9
|
type SixbHostView,
|
|
10
10
|
} from "@sixb/core"
|
|
11
|
+
import {
|
|
12
|
+
AgentExecutionLostError,
|
|
13
|
+
type AgentRunArtifacts,
|
|
14
|
+
agentRunArtifacts,
|
|
15
|
+
} from "@sixb/core/internal/agents"
|
|
11
16
|
import {
|
|
12
17
|
createArtifactFrame,
|
|
13
18
|
serializeArtifactQueryResult,
|
|
@@ -15,7 +20,7 @@ import {
|
|
|
15
20
|
import type { Elysia } from "elysia"
|
|
16
21
|
import { ZodError } from "zod"
|
|
17
22
|
import { accessTokenSecurityRequirement } from "../auth/access-token-boundary"
|
|
18
|
-
import { requireRequestSixb } from "../auth/scope"
|
|
23
|
+
import { requestAuthState, requireRequestSixb } from "../auth/scope"
|
|
19
24
|
import {
|
|
20
25
|
createFileContentResponse,
|
|
21
26
|
fileContentGetResponses,
|
|
@@ -107,6 +112,33 @@ function contentInput(body: {
|
|
|
107
112
|
}
|
|
108
113
|
}
|
|
109
114
|
|
|
115
|
+
/**
|
|
116
|
+
* What a request with a run token publishes through: its run's conversation, by a run's rules
|
|
117
|
+
* (`AgentRunArtifacts.publish`), as the run's session does in a worker. `null` for any other
|
|
118
|
+
* caller, who publishes as themselves.
|
|
119
|
+
*/
|
|
120
|
+
async function runTokenArtifacts(
|
|
121
|
+
host: SixbHostView,
|
|
122
|
+
context: unknown
|
|
123
|
+
): Promise<AgentRunArtifacts | null> {
|
|
124
|
+
const { agentExecution, sixb } = requestAuthState(context)
|
|
125
|
+
if (!agentExecution) return null
|
|
126
|
+
if (agentExecution.kind === "workflow") {
|
|
127
|
+
throw new ArtifactRequestError(
|
|
128
|
+
"not_allowed",
|
|
129
|
+
"[SixbServer] Workflow agent nodes publish no artifacts: they have no conversation."
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
// Fenced with the execution the request was admitted under: a run reclaimed since refuses it.
|
|
133
|
+
const { runId, executionToken } = agentExecution
|
|
134
|
+
const run = await host.storage.agents?.runs.getById({ projectId: host.id, id: runId })
|
|
135
|
+
if (!run || !sixb) throw new AgentExecutionLostError(runId)
|
|
136
|
+
|
|
137
|
+
return agentRunArtifacts({ projectId: host.id, storage: host.storage }, run, executionToken, () =>
|
|
138
|
+
Promise.resolve(sixb)
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
|
|
110
142
|
function versionParam(value: string): number | "latest" {
|
|
111
143
|
return value === "latest" ? "latest" : Number(value)
|
|
112
144
|
}
|
|
@@ -169,6 +201,13 @@ function handleArtifactRouteError(error: unknown, set: RouteSet) {
|
|
|
169
201
|
...(error.latest ? { latest: error.latest } : {}),
|
|
170
202
|
}
|
|
171
203
|
}
|
|
204
|
+
if (error instanceof AgentExecutionLostError) {
|
|
205
|
+
set.status = 409
|
|
206
|
+
return {
|
|
207
|
+
error: "[SixbServer] The run has ended or moved to another runner, so nothing was published.",
|
|
208
|
+
code: "execution_lost",
|
|
209
|
+
}
|
|
210
|
+
}
|
|
172
211
|
if (error instanceof ZodError) {
|
|
173
212
|
set.status = 400
|
|
174
213
|
return { error: "Invalid artifact request" }
|
|
@@ -283,7 +322,10 @@ export function registerArtifactRoutes(app: Elysia, host: SixbHostView) {
|
|
|
283
322
|
async (context) => {
|
|
284
323
|
try {
|
|
285
324
|
const body = PublishArtifactBodySchema.parse(context.body)
|
|
286
|
-
const
|
|
325
|
+
const run = await runTokenArtifacts(host, context)
|
|
326
|
+
const published = run
|
|
327
|
+
? await run.publish(contentInput(body))
|
|
328
|
+
: await requireRequestSixb(context).artifacts.create(contentInput(body))
|
|
287
329
|
context.set.status = 201
|
|
288
330
|
return serializePublished(published)
|
|
289
331
|
} catch (error) {
|
|
@@ -296,7 +338,7 @@ export function registerArtifactRoutes(app: Elysia, host: SixbHostView) {
|
|
|
296
338
|
detail: {
|
|
297
339
|
summary: "Create an artifact",
|
|
298
340
|
description:
|
|
299
|
-
"Creates an artifact owned by the caller, with its first version. Store each file with POST /api/files first.",
|
|
341
|
+
"Creates an artifact owned by the caller, with its first version. Store each file with POST /api/files first. With a run token, it is created in the run's conversation, owned by the conversation's owner and authored by the run's requester.",
|
|
300
342
|
tags: [OPENAPI_TAGS.artifacts.name],
|
|
301
343
|
operationId: "createArtifact",
|
|
302
344
|
security: accessTokenSecurityRequirement("createArtifact"),
|
|
@@ -525,13 +567,15 @@ export function registerArtifactRoutes(app: Elysia, host: SixbHostView) {
|
|
|
525
567
|
async (context) => {
|
|
526
568
|
try {
|
|
527
569
|
const body = PublishArtifactVersionBodySchema.parse(context.body)
|
|
528
|
-
const
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
570
|
+
const { artifactId } = context.params
|
|
571
|
+
const content = {
|
|
572
|
+
...contentInput(body),
|
|
573
|
+
...(body.baseVersion === undefined ? {} : { baseVersion: body.baseVersion }),
|
|
574
|
+
}
|
|
575
|
+
const run = await runTokenArtifacts(host, context)
|
|
576
|
+
const published = run
|
|
577
|
+
? await run.publish({ ...content, artifactId })
|
|
578
|
+
: await requireRequestSixb(context).artifacts.publish(artifactId, content)
|
|
535
579
|
context.set.status = 201
|
|
536
580
|
return serializePublished(published)
|
|
537
581
|
} catch (error) {
|
|
@@ -545,7 +589,7 @@ export function registerArtifactRoutes(app: Elysia, host: SixbHostView) {
|
|
|
545
589
|
detail: {
|
|
546
590
|
summary: "Publish an artifact's next version",
|
|
547
591
|
description:
|
|
548
|
-
"The kind must be the artifact's. The new version becomes the latest. With baseVersion, it is refused with 409 artifact_moved when another version was published since.",
|
|
592
|
+
"The kind must be the artifact's. The new version becomes the latest. With baseVersion, it is refused with 409 artifact_moved when another version was published since. With a run token, only an artifact the run's conversation shares or its requester owns; the version is shared in that conversation. A run that lost its execution gets 409 execution_lost.",
|
|
549
593
|
tags: [OPENAPI_TAGS.artifacts.name],
|
|
550
594
|
operationId: "publishArtifactVersion",
|
|
551
595
|
security: accessTokenSecurityRequirement("publishArtifactVersion"),
|
package/src/routes/auth.ts
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
verifyCsrfToken,
|
|
25
25
|
verifyDoubleSubmitCsrf,
|
|
26
26
|
} from "@sixb/core/internal/auth"
|
|
27
|
+
import { isAllowed } from "@sixb/core/internal/authorization"
|
|
27
28
|
import {
|
|
28
29
|
type AccessTokenRecord,
|
|
29
30
|
type AuthStorage,
|
|
@@ -119,6 +120,14 @@ type AuthenticatedAuthSessionResponse = {
|
|
|
119
120
|
readonly avatarUrl?: string
|
|
120
121
|
readonly groupIds: readonly string[]
|
|
121
122
|
}
|
|
123
|
+
readonly access: {
|
|
124
|
+
readonly members: boolean
|
|
125
|
+
readonly serviceAccounts: boolean
|
|
126
|
+
readonly usage: boolean
|
|
127
|
+
readonly activity: boolean
|
|
128
|
+
readonly console: boolean
|
|
129
|
+
readonly logs: boolean
|
|
130
|
+
}
|
|
122
131
|
readonly session: {
|
|
123
132
|
readonly id: string
|
|
124
133
|
readonly expiresAt: string
|
|
@@ -588,7 +597,7 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
|
|
|
588
597
|
return signedOutSessionResponse(host)
|
|
589
598
|
}
|
|
590
599
|
if (caller.session.bearer) {
|
|
591
|
-
return jsonResponse(authSessionBody(caller), 200)
|
|
600
|
+
return jsonResponse(authSessionBody(host, caller), 200)
|
|
592
601
|
}
|
|
593
602
|
|
|
594
603
|
const session = hasForegroundSessionActivity(request)
|
|
@@ -614,7 +623,7 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
|
|
|
614
623
|
})
|
|
615
624
|
: null
|
|
616
625
|
return authSessionJsonResponse(
|
|
617
|
-
{ ...authSessionBody(session), csrfToken: csrf.token },
|
|
626
|
+
{ ...authSessionBody(host, session), csrfToken: csrf.token },
|
|
618
627
|
renewal?.headers ?? (csrf.setCookie ? [csrf.setCookie] : [])
|
|
619
628
|
)
|
|
620
629
|
},
|
|
@@ -2325,8 +2334,12 @@ function resolveSessionCsrfToken(input: {
|
|
|
2325
2334
|
}
|
|
2326
2335
|
|
|
2327
2336
|
function authSessionBody(
|
|
2337
|
+
host: SixbHostView,
|
|
2328
2338
|
session: AuthenticatedAuthSession
|
|
2329
2339
|
): Omit<AuthenticatedAuthSessionResponse, "csrfToken"> {
|
|
2340
|
+
// The same policies and grants the pages' own routes check.
|
|
2341
|
+
const capabilities = host.auth.getMembershipCapabilities({ callerGroups: session.groupIds }).holds
|
|
2342
|
+
const authorization = host.auth.contextFromSession(session)
|
|
2330
2343
|
return {
|
|
2331
2344
|
authenticated: true,
|
|
2332
2345
|
user: {
|
|
@@ -2336,6 +2349,14 @@ function authSessionBody(
|
|
|
2336
2349
|
avatarUrl: session.user.avatarUrl,
|
|
2337
2350
|
groupIds: [...session.groupIds],
|
|
2338
2351
|
},
|
|
2352
|
+
access: {
|
|
2353
|
+
members: capabilities.invite || capabilities.assignGroups || capabilities.suspend,
|
|
2354
|
+
serviceAccounts: capabilities.serviceAccounts,
|
|
2355
|
+
usage: isAllowed(authorization, { kind: "aiUsage.observe" }),
|
|
2356
|
+
activity: isAllowed(authorization, { kind: "activity.observe" }),
|
|
2357
|
+
console: isAllowed(authorization, { kind: "console.observe" }),
|
|
2358
|
+
logs: isAllowed(authorization, { kind: "logs.observe" }),
|
|
2359
|
+
},
|
|
2339
2360
|
session: { id: session.session.id, expiresAt: toIsoString(session.session.expiresAt) },
|
|
2340
2361
|
}
|
|
2341
2362
|
}
|
|
@@ -3105,6 +3126,7 @@ function serializeMemberSummary(member: MemberSummary) {
|
|
|
3105
3126
|
return {
|
|
3106
3127
|
...serializeManagedMember(member),
|
|
3107
3128
|
capabilities: member.capabilities,
|
|
3129
|
+
...(member.lastActiveAt ? { lastActiveAt: toIsoString(member.lastActiveAt) } : {}),
|
|
3108
3130
|
}
|
|
3109
3131
|
}
|
|
3110
3132
|
|
package/src/routes/datasets.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DatasetDefinition, SixbHostView } from "@sixb/core"
|
|
1
|
+
import type { DatasetDefinition, DatasetLineage, SixbHostView } from "@sixb/core"
|
|
2
2
|
import { createSixbError } from "@sixb/core/internal/errors"
|
|
3
3
|
import type {
|
|
4
4
|
DatasetCatalogState,
|
|
@@ -6,11 +6,14 @@ import type {
|
|
|
6
6
|
DatasetVersion,
|
|
7
7
|
} from "@sixb/core/lake-storage"
|
|
8
8
|
import type { Elysia } from "elysia"
|
|
9
|
+
import { accessTokenSecurityRequirement } from "../auth/access-token-boundary"
|
|
9
10
|
import { requireRequestSixb } from "../auth/scope"
|
|
10
11
|
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
11
12
|
import { codedErrorResponseSchema, ErrorResponseSchema } from "../schemas/common"
|
|
12
13
|
import {
|
|
13
14
|
DatasetCatalogItemSchema,
|
|
15
|
+
DatasetLineageQuerySchema,
|
|
16
|
+
DatasetLineageResponseSchema,
|
|
14
17
|
DatasetParamsSchema,
|
|
15
18
|
DatasetRowsQuerySchema,
|
|
16
19
|
DatasetRowsResponseSchema,
|
|
@@ -63,6 +66,15 @@ function serializeDatasetVersion(version: DatasetVersion) {
|
|
|
63
66
|
})
|
|
64
67
|
}
|
|
65
68
|
|
|
69
|
+
function serializeDatasetLineage(lineage: DatasetLineage) {
|
|
70
|
+
return DatasetLineageResponseSchema.parse({
|
|
71
|
+
...lineage,
|
|
72
|
+
nodes: lineage.nodes.map((node) =>
|
|
73
|
+
"expired" in node ? node : { ...node, createdAt: toIsoString(node.createdAt) }
|
|
74
|
+
),
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
66
78
|
interface DatasetReferences {
|
|
67
79
|
readonly syncIds: string[]
|
|
68
80
|
readonly sourcePipelineIds: string[]
|
|
@@ -213,6 +225,7 @@ export function registerDatasetRoutes(app: Elysia, host: SixbHostView) {
|
|
|
213
225
|
summary: "List registered datasets",
|
|
214
226
|
tags: [OPENAPI_TAGS.datasets.name],
|
|
215
227
|
operationId: "listDatasets",
|
|
228
|
+
security: accessTokenSecurityRequirement("listDatasets"),
|
|
216
229
|
},
|
|
217
230
|
}
|
|
218
231
|
)
|
|
@@ -241,6 +254,7 @@ export function registerDatasetRoutes(app: Elysia, host: SixbHostView) {
|
|
|
241
254
|
summary: "Get dataset metadata",
|
|
242
255
|
tags: [OPENAPI_TAGS.datasets.name],
|
|
243
256
|
operationId: "getDataset",
|
|
257
|
+
security: accessTokenSecurityRequirement("getDataset"),
|
|
244
258
|
},
|
|
245
259
|
}
|
|
246
260
|
)
|
|
@@ -250,10 +264,10 @@ export function registerDatasetRoutes(app: Elysia, host: SixbHostView) {
|
|
|
250
264
|
const { params, query, set } = context
|
|
251
265
|
const sixb = requireRequestSixb(context)
|
|
252
266
|
try {
|
|
253
|
-
requireDataset(sixb, params.datasetId)
|
|
267
|
+
const dataset = requireDataset(sixb, params.datasetId)
|
|
254
268
|
const parsed = DatasetVersionsQuerySchema.parse(query)
|
|
255
269
|
const limit = parseLimit(parsed.limit, DEFAULT_VERSION_LIMIT, MAX_VERSION_LIMIT)
|
|
256
|
-
const versions = await
|
|
270
|
+
const versions = await sixb.datasets.listVersions(dataset, { limit })
|
|
257
271
|
|
|
258
272
|
return DatasetVersionListResponseSchema.parse({
|
|
259
273
|
versions: versions.map(serializeDatasetVersion),
|
|
@@ -275,6 +289,7 @@ export function registerDatasetRoutes(app: Elysia, host: SixbHostView) {
|
|
|
275
289
|
summary: "List dataset versions",
|
|
276
290
|
tags: [OPENAPI_TAGS.datasetVersions.name],
|
|
277
291
|
operationId: "listDatasetVersions",
|
|
292
|
+
security: accessTokenSecurityRequirement("listDatasetVersions"),
|
|
278
293
|
},
|
|
279
294
|
}
|
|
280
295
|
)
|
|
@@ -284,8 +299,8 @@ export function registerDatasetRoutes(app: Elysia, host: SixbHostView) {
|
|
|
284
299
|
const { params, set } = context
|
|
285
300
|
const sixb = requireRequestSixb(context)
|
|
286
301
|
try {
|
|
287
|
-
requireDataset(sixb, params.datasetId)
|
|
288
|
-
const version = await
|
|
302
|
+
const dataset = requireDataset(sixb, params.datasetId)
|
|
303
|
+
const version = await sixb.datasets.getVersion(dataset, params.versionId)
|
|
289
304
|
if (!version) {
|
|
290
305
|
throw datasetVersionNotFound(params.datasetId, params.versionId)
|
|
291
306
|
}
|
|
@@ -309,6 +324,45 @@ export function registerDatasetRoutes(app: Elysia, host: SixbHostView) {
|
|
|
309
324
|
},
|
|
310
325
|
}
|
|
311
326
|
)
|
|
327
|
+
.get(
|
|
328
|
+
"/api/datasets/:datasetId/versions/:versionId/lineage",
|
|
329
|
+
async (context) => {
|
|
330
|
+
const { params, query, set } = context
|
|
331
|
+
const sixb = requireRequestSixb(context)
|
|
332
|
+
try {
|
|
333
|
+
const dataset = requireDataset(sixb, params.datasetId)
|
|
334
|
+
const parsed = DatasetLineageQuerySchema.parse(query)
|
|
335
|
+
const lineage = await sixb.datasets.lineage(dataset, {
|
|
336
|
+
versionId: params.versionId,
|
|
337
|
+
depth: parseOptionalInt(parsed.depth),
|
|
338
|
+
})
|
|
339
|
+
if (!lineage) {
|
|
340
|
+
throw datasetVersionNotFound(params.datasetId, params.versionId)
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return serializeDatasetLineage(lineage)
|
|
344
|
+
} catch (error) {
|
|
345
|
+
return handleRouteError(error, set)
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
params: DatasetVersionParamsSchema,
|
|
350
|
+
query: DatasetLineageQuerySchema,
|
|
351
|
+
response: {
|
|
352
|
+
200: DatasetLineageResponseSchema,
|
|
353
|
+
400: ErrorResponseSchema,
|
|
354
|
+
404: DatasetVersionNotFoundErrorResponseSchema,
|
|
355
|
+
},
|
|
356
|
+
detail: {
|
|
357
|
+
summary: "Get the versions a dataset version is computed from",
|
|
358
|
+
description:
|
|
359
|
+
"Walks the version's inputs upstream, `depth` steps (1 to 20, default 5). A version whose dataset the caller cannot view is left out with everything upstream of it, and counted in `restricted`.",
|
|
360
|
+
tags: [OPENAPI_TAGS.datasetVersions.name],
|
|
361
|
+
operationId: "getDatasetVersionLineage",
|
|
362
|
+
security: accessTokenSecurityRequirement("getDatasetVersionLineage"),
|
|
363
|
+
},
|
|
364
|
+
}
|
|
365
|
+
)
|
|
312
366
|
.get(
|
|
313
367
|
"/api/datasets/:datasetId/rows",
|
|
314
368
|
async (context) => {
|
|
@@ -366,6 +420,7 @@ export function registerDatasetRoutes(app: Elysia, host: SixbHostView) {
|
|
|
366
420
|
summary: "Preview dataset rows",
|
|
367
421
|
tags: [OPENAPI_TAGS.datasetRows.name],
|
|
368
422
|
operationId: "listDatasetRows",
|
|
423
|
+
security: accessTokenSecurityRequirement("listDatasetRows"),
|
|
369
424
|
},
|
|
370
425
|
}
|
|
371
426
|
)
|