@sixb/server 0.1.19 → 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/README.md +13 -22
- package/dist/artifacts/frame.d.ts +13 -0
- package/dist/artifacts/frame.d.ts.map +1 -0
- package/dist/auth/browser-origin.d.ts +9 -26
- package/dist/auth/browser-origin.d.ts.map +1 -1
- package/dist/auth/experience.d.ts +0 -3
- package/dist/auth/experience.d.ts.map +1 -1
- package/dist/auth/guard.d.ts +1 -1
- package/dist/auth/guard.d.ts.map +1 -1
- package/dist/auth/public-routes.d.ts +0 -5
- package/dist/auth/public-routes.d.ts.map +1 -1
- package/dist/auth/responses.d.ts +0 -2
- package/dist/auth/responses.d.ts.map +1 -1
- package/dist/auth/session-cookies.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.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3241 -2445
- package/dist/index.js.map +31 -26
- 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/action-runs.d.ts +0 -2
- package/dist/routes/action-runs.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 -29
- 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 +9 -18
- package/dist/routes/auth.d.ts.map +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/objects.d.ts +0 -2
- package/dist/routes/objects.d.ts.map +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 -34
- package/dist/routes/workflows.d.ts.map +1 -1
- 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 +34 -69
- package/dist/schemas/auth.d.ts.map +1 -1
- 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/files.d.ts +0 -3
- package/dist/schemas/files.d.ts.map +1 -1
- 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 +1 -2
- package/dist/server.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/artifacts/frame.ts +46 -0
- package/src/auth/browser-origin.ts +40 -240
- package/src/auth/experience.ts +1 -4
- package/src/auth/guard.ts +4 -32
- package/src/auth/public-routes.ts +11 -10
- package/src/auth/responses.ts +0 -5
- package/src/auth/session-cookies.ts +1 -3
- package/src/auth/shared-access.ts +1 -1
- package/src/files/content.ts +9 -13
- package/src/index.ts +1 -1
- 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/auth.ts +32 -111
- 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/schemas/auth.ts +2 -15
- package/src/schemas/files.ts +0 -6
- package/src/server.ts +27 -24
- package/dist/auth/application-access.d.ts +0 -4
- package/dist/auth/application-access.d.ts.map +0 -1
- package/src/auth/application-access.ts +0 -15
package/src/files/content.ts
CHANGED
|
@@ -15,9 +15,8 @@ export interface FileContentResponseInput {
|
|
|
15
15
|
readonly fileRef: FileRef
|
|
16
16
|
readonly disposition?: FileContentDisposition
|
|
17
17
|
readonly head?: boolean
|
|
18
|
-
|
|
19
|
-
readonly
|
|
20
|
-
readonly ifRangeHeader?: string | null
|
|
18
|
+
/** The request being answered: its Range, If-Range, and If-None-Match headers apply. */
|
|
19
|
+
readonly request?: Request
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
export interface FileContentQuery {
|
|
@@ -161,18 +160,17 @@ export async function createFileContentResponse(
|
|
|
161
160
|
const canReadRange = supportsRangeRead(input.blobStorage)
|
|
162
161
|
const headers = fileContentHeaders(input.fileRef, stat, input.disposition, canReadRange)
|
|
163
162
|
const etag = headers.get("etag")!
|
|
164
|
-
|
|
163
|
+
const requestHeaders = input.request?.headers
|
|
164
|
+
if (matchesIfNoneMatch(requestHeaders?.get("if-none-match"), etag)) {
|
|
165
165
|
headers.delete("content-length")
|
|
166
166
|
return new Response(null, { status: 304, headers })
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
// Date validators are unsupported: only a strong ETag can validate a range.
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
) {
|
|
175
|
-
const range = parseSingleByteRange(input.rangeHeader, stat.sizeBytes)
|
|
170
|
+
const rangeHeader = requestHeaders?.get("range")
|
|
171
|
+
const ifRangeHeader = requestHeaders?.get("if-range")
|
|
172
|
+
if (canReadRange && rangeHeader && (ifRangeHeader == null || ifRangeHeader.trim() === etag)) {
|
|
173
|
+
const range = parseSingleByteRange(rangeHeader, stat.sizeBytes)
|
|
176
174
|
if (!range) {
|
|
177
175
|
return rangeNotSatisfiableResponse(stat.sizeBytes)
|
|
178
176
|
}
|
|
@@ -237,9 +235,7 @@ export async function createContextualFileContentResponse<TQuery extends FileCon
|
|
|
237
235
|
fileRef,
|
|
238
236
|
disposition: parsed.disposition,
|
|
239
237
|
head: input.head,
|
|
240
|
-
|
|
241
|
-
ifNoneMatchHeader: input.request.headers.get("if-none-match"),
|
|
242
|
-
ifRangeHeader: input.request.headers.get("if-range"),
|
|
238
|
+
request: input.request,
|
|
243
239
|
})
|
|
244
240
|
if (!response) {
|
|
245
241
|
return fileContentNotFound(input.set, missingMessage)
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { SixbApiBrowserPolicy
|
|
1
|
+
export type { SixbApiBrowserPolicy } from "./auth/browser-origin"
|
|
2
2
|
export type { SixbAuthExperienceOptions } from "./auth/experience"
|
|
3
3
|
export type { SixbSharedAccessOptions } from "./auth/shared-access"
|
|
4
4
|
export { createSixbServer, SixbServer, type SixbServerOptions } from "./server"
|
package/src/openapi/tags.ts
CHANGED
|
@@ -123,6 +123,10 @@ export const OPENAPI_TAGS = {
|
|
|
123
123
|
name: "Files",
|
|
124
124
|
description: "File uploads and file references",
|
|
125
125
|
},
|
|
126
|
+
artifacts: {
|
|
127
|
+
name: "Artifacts",
|
|
128
|
+
description: "Versioned documents, sheets, slides, pages, and files",
|
|
129
|
+
},
|
|
126
130
|
links: {
|
|
127
131
|
name: "Links",
|
|
128
132
|
description: "Object relationship links",
|
|
@@ -139,6 +143,10 @@ export const OPENAPI_TAGS = {
|
|
|
139
143
|
name: "Logs",
|
|
140
144
|
description: "Run log stream",
|
|
141
145
|
},
|
|
146
|
+
activity: {
|
|
147
|
+
name: "Activity",
|
|
148
|
+
description: "Visits and page views in the project's app and its shared links",
|
|
149
|
+
},
|
|
142
150
|
authSessions: {
|
|
143
151
|
name: "Auth Sessions",
|
|
144
152
|
description: "Authentication sessions and sign-out",
|
package/src/registerRoutes.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { SixbHostView } from "@sixb/core"
|
|
2
2
|
import type { Elysia } from "elysia"
|
|
3
|
+
import type { ResolvedSixbApiBrowserPolicy } from "./auth/browser-origin"
|
|
3
4
|
import type { SharedAccessBoundary } from "./auth/shared-access"
|
|
4
5
|
import { registerActionRunRoutes } from "./routes/action-runs"
|
|
5
6
|
import { registerActionRoutes } from "./routes/actions"
|
|
7
|
+
import { registerActivityRoutes } from "./routes/activity"
|
|
6
8
|
import { registerAgentApiGatewayRoutes } from "./routes/agent-api-gateway"
|
|
7
9
|
import { registerAgentRoutes } from "./routes/agents"
|
|
8
10
|
import { registerAiAccountingRoutes } from "./routes/ai-accounting"
|
|
11
|
+
import { registerArtifactFrameRoutes } from "./routes/artifact-frames"
|
|
12
|
+
import { registerArtifactRoutes } from "./routes/artifacts"
|
|
9
13
|
import {
|
|
10
14
|
type ConnectorConnectionRouteOptions,
|
|
11
15
|
registerConnectorConnectionRunRoutes,
|
|
@@ -36,6 +40,8 @@ import { registerWorkflowRoutes } from "./routes/workflows"
|
|
|
36
40
|
export interface HttpRouteOptions {
|
|
37
41
|
readonly connectorConnections: ConnectorConnectionRouteOptions
|
|
38
42
|
readonly sharedAccess: SharedAccessBoundary
|
|
43
|
+
/** Where frames are served from and which app origins may show them. */
|
|
44
|
+
readonly browserPolicy: ResolvedSixbApiBrowserPolicy
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
export function registerHttpRoutes(app: Elysia, host: SixbHostView, options: HttpRouteOptions) {
|
|
@@ -60,11 +66,14 @@ export function registerHttpRoutes(app: Elysia, host: SixbHostView, options: Htt
|
|
|
60
66
|
registerFileDownloadRoutes(app, host)
|
|
61
67
|
registerActionRunRoutes(app, host)
|
|
62
68
|
registerAgentRoutes(app, host)
|
|
69
|
+
registerArtifactRoutes(app, host)
|
|
70
|
+
registerArtifactFrameRoutes(app, host, options.browserPolicy)
|
|
63
71
|
registerModelRoutes(app, host)
|
|
64
72
|
registerLinkRoutes(app, host)
|
|
65
73
|
registerTelemetryRoutes(app, host)
|
|
66
74
|
registerEventRoutes(app, host)
|
|
67
75
|
registerLogRoutes(app, host)
|
|
76
|
+
registerActivityRoutes(app, host)
|
|
68
77
|
registerProjectionRoutes(app, host)
|
|
69
78
|
registerWebhookRunRoutes(app, host)
|
|
70
79
|
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ActivityConnection,
|
|
3
|
+
type ActivityTimelineEntry,
|
|
4
|
+
type ActivityVisitTimeline,
|
|
5
|
+
type ActivityVisitView,
|
|
6
|
+
AuthorizationError,
|
|
7
|
+
type SixbHostView,
|
|
8
|
+
} from "@sixb/core"
|
|
9
|
+
import { getActivityCaptureRuntime } from "@sixb/core/internal/runtime"
|
|
10
|
+
import type { Elysia } from "elysia"
|
|
11
|
+
import { accessTokenSecurityRequirement, credentialTransport } from "../auth/access-token-boundary"
|
|
12
|
+
import { requestCaller, requireRequestSixb } from "../auth/scope"
|
|
13
|
+
import {
|
|
14
|
+
SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT,
|
|
15
|
+
SIXB_SESSION_SECURITY_REQUIREMENT,
|
|
16
|
+
SIXB_SHARED_MUTATION_SECURITY_REQUIREMENT,
|
|
17
|
+
SIXB_SHARED_READ_SECURITY_REQUIREMENT,
|
|
18
|
+
} from "../openapi/security"
|
|
19
|
+
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
20
|
+
import {
|
|
21
|
+
ActivityCalendarQuerySchema,
|
|
22
|
+
ActivityCalendarSchema,
|
|
23
|
+
ActivityCaptureOptionsSchema,
|
|
24
|
+
ActivityCaptureResultSchema,
|
|
25
|
+
ActivityConnectionsPageSchema,
|
|
26
|
+
ActivityConnectionsQuerySchema,
|
|
27
|
+
ActivityPageQuerySchema,
|
|
28
|
+
ActivityPeriodQuerySchema,
|
|
29
|
+
ActivitySummarySchema,
|
|
30
|
+
ActivityUsersPageSchema,
|
|
31
|
+
ActivityVisitParamsSchema,
|
|
32
|
+
ActivityVisitsPageSchema,
|
|
33
|
+
ActivityVisitTimelineSchema,
|
|
34
|
+
CaptureActivityBodySchema,
|
|
35
|
+
} from "../schemas/activity"
|
|
36
|
+
import { ErrorResponseSchema } from "../schemas/common"
|
|
37
|
+
import { handleRouteError } from "../utils/http"
|
|
38
|
+
|
|
39
|
+
const errors = { 400: ErrorResponseSchema, 403: ErrorResponseSchema }
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Recording and reading take different authority: a browser session records only its own visits,
|
|
43
|
+
* and reading needs `can.observe(project.activity)`.
|
|
44
|
+
*/
|
|
45
|
+
export function registerActivityRoutes(app: Elysia, _host: SixbHostView) {
|
|
46
|
+
app.get(
|
|
47
|
+
"/api/activity/capture-config",
|
|
48
|
+
(context) => {
|
|
49
|
+
try {
|
|
50
|
+
assertBrowserCapture(context)
|
|
51
|
+
return getActivityCaptureRuntime(requireRequestSixb(context)).captureOptions()
|
|
52
|
+
} catch (error) {
|
|
53
|
+
return handleRouteError(error, context.set)
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
response: { 200: ActivityCaptureOptionsSchema, ...errors },
|
|
58
|
+
detail: {
|
|
59
|
+
summary: "Read whether this browser session records activity",
|
|
60
|
+
description: "A browser or shared-link session only; a native client's session gets 403.",
|
|
61
|
+
tags: [OPENAPI_TAGS.activity.name],
|
|
62
|
+
operationId: "getActivityCaptureConfig",
|
|
63
|
+
security: [...SIXB_SESSION_SECURITY_REQUIREMENT, SIXB_SHARED_READ_SECURITY_REQUIREMENT],
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
app.post(
|
|
69
|
+
"/api/activity/events",
|
|
70
|
+
async (context) => {
|
|
71
|
+
try {
|
|
72
|
+
assertBrowserCapture(context)
|
|
73
|
+
const capture = getActivityCaptureRuntime(requireRequestSixb(context))
|
|
74
|
+
const result = await capture.capture(context.body.events)
|
|
75
|
+
|
|
76
|
+
if (result.status === "throttled") {
|
|
77
|
+
context.set.status = 429
|
|
78
|
+
context.set.headers["retry-after"] = "60"
|
|
79
|
+
}
|
|
80
|
+
return result
|
|
81
|
+
} catch (error) {
|
|
82
|
+
return handleRouteError(error, context.set)
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
body: CaptureActivityBodySchema,
|
|
87
|
+
response: { 200: ActivityCaptureResultSchema, 429: ActivityCaptureResultSchema, ...errors },
|
|
88
|
+
detail: {
|
|
89
|
+
summary: "Record page views, activity and interactions for this browser session",
|
|
90
|
+
description:
|
|
91
|
+
"A browser or shared-link session only; a native client's session gets 403. The visit belongs to the calling session.",
|
|
92
|
+
tags: [OPENAPI_TAGS.activity.name],
|
|
93
|
+
operationId: "captureActivity",
|
|
94
|
+
security: [
|
|
95
|
+
...SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT,
|
|
96
|
+
SIXB_SHARED_MUTATION_SECURITY_REQUIREMENT,
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
app.get(
|
|
103
|
+
"/api/activity/visits",
|
|
104
|
+
async (context) => {
|
|
105
|
+
try {
|
|
106
|
+
const page = await requireRequestSixb(context).activity.list(pageQuery(context.query))
|
|
107
|
+
return { visits: page.visits.map(serializeVisit), hasMore: page.hasMore }
|
|
108
|
+
} catch (error) {
|
|
109
|
+
return handleRouteError(error, context.set)
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
query: ActivityPageQuerySchema,
|
|
114
|
+
response: { 200: ActivityVisitsPageSchema, ...errors },
|
|
115
|
+
detail: {
|
|
116
|
+
summary: "List the visits active in a period",
|
|
117
|
+
tags: [OPENAPI_TAGS.activity.name],
|
|
118
|
+
operationId: "listActivityVisits",
|
|
119
|
+
security: accessTokenSecurityRequirement("listActivityVisits"),
|
|
120
|
+
},
|
|
121
|
+
}
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
app.get(
|
|
125
|
+
"/api/activity/users",
|
|
126
|
+
async (context) => {
|
|
127
|
+
try {
|
|
128
|
+
const page = await requireRequestSixb(context).activity.users(pageQuery(context.query))
|
|
129
|
+
return {
|
|
130
|
+
users: page.users.map((user) => ({ ...user, lastSeenAt: user.lastSeenAt.toISOString() })),
|
|
131
|
+
hasMore: page.hasMore,
|
|
132
|
+
}
|
|
133
|
+
} catch (error) {
|
|
134
|
+
return handleRouteError(error, context.set)
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
query: ActivityPageQuerySchema,
|
|
139
|
+
response: { 200: ActivityUsersPageSchema, ...errors },
|
|
140
|
+
detail: {
|
|
141
|
+
summary: "List the signed-in users active in a period",
|
|
142
|
+
tags: [OPENAPI_TAGS.activity.name],
|
|
143
|
+
operationId: "listActivityUsers",
|
|
144
|
+
security: accessTokenSecurityRequirement("listActivityUsers"),
|
|
145
|
+
},
|
|
146
|
+
}
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
app.get(
|
|
150
|
+
"/api/activity/summary",
|
|
151
|
+
async (context) => {
|
|
152
|
+
try {
|
|
153
|
+
return await requireRequestSixb(context).activity.summarize({
|
|
154
|
+
from: new Date(context.query.from),
|
|
155
|
+
to: new Date(context.query.to),
|
|
156
|
+
userId: context.query.userId,
|
|
157
|
+
})
|
|
158
|
+
} catch (error) {
|
|
159
|
+
return handleRouteError(error, context.set)
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
query: ActivityPeriodQuerySchema,
|
|
164
|
+
response: { 200: ActivitySummarySchema, ...errors },
|
|
165
|
+
detail: {
|
|
166
|
+
summary: "Count the users, visits and page views of a period",
|
|
167
|
+
tags: [OPENAPI_TAGS.activity.name],
|
|
168
|
+
operationId: "getActivitySummary",
|
|
169
|
+
security: accessTokenSecurityRequirement("getActivitySummary"),
|
|
170
|
+
},
|
|
171
|
+
}
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
app.get(
|
|
175
|
+
"/api/activity/calendar",
|
|
176
|
+
async (context) => {
|
|
177
|
+
try {
|
|
178
|
+
const calendar = await requireRequestSixb(context).activity.calendar(context.query)
|
|
179
|
+
return { ...calendar, days: [...calendar.days] }
|
|
180
|
+
} catch (error) {
|
|
181
|
+
return handleRouteError(error, context.set)
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
query: ActivityCalendarQuerySchema,
|
|
186
|
+
response: { 200: ActivityCalendarSchema, ...errors },
|
|
187
|
+
detail: {
|
|
188
|
+
summary: "Read a user's active days in a UTC year",
|
|
189
|
+
tags: [OPENAPI_TAGS.activity.name],
|
|
190
|
+
operationId: "getActivityCalendar",
|
|
191
|
+
security: accessTokenSecurityRequirement("getActivityCalendar"),
|
|
192
|
+
},
|
|
193
|
+
}
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
app.get(
|
|
197
|
+
"/api/activity/visits/:visitId/timeline",
|
|
198
|
+
async (context) => {
|
|
199
|
+
try {
|
|
200
|
+
const timeline = await requireRequestSixb(context).activity.timeline(context.params.visitId)
|
|
201
|
+
if (!timeline) {
|
|
202
|
+
context.set.status = 404
|
|
203
|
+
return { error: "Activity visit not found" }
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return serializeTimeline(timeline)
|
|
207
|
+
} catch (error) {
|
|
208
|
+
return handleRouteError(error, context.set)
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
params: ActivityVisitParamsSchema,
|
|
213
|
+
response: { 200: ActivityVisitTimelineSchema, 404: ErrorResponseSchema, ...errors },
|
|
214
|
+
detail: {
|
|
215
|
+
summary: "Read what one visit did",
|
|
216
|
+
description:
|
|
217
|
+
"Its page views and interactions, with the actions, workflows and Agent runs its session started, and the connection it came through. At most 200 page views and interactions, and 200 recorded executions: see truncated.",
|
|
218
|
+
tags: [OPENAPI_TAGS.activity.name],
|
|
219
|
+
operationId: "getActivityVisitTimeline",
|
|
220
|
+
security: accessTokenSecurityRequirement("getActivityVisitTimeline"),
|
|
221
|
+
},
|
|
222
|
+
}
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
app.get(
|
|
226
|
+
"/api/activity/connections",
|
|
227
|
+
async (context) => {
|
|
228
|
+
try {
|
|
229
|
+
const page = await requireRequestSixb(context).activity.connections(context.query)
|
|
230
|
+
return {
|
|
231
|
+
connections: page.connections.map((connection) => ({
|
|
232
|
+
...serializeConnection(connection),
|
|
233
|
+
latestVisits: connection.latestVisits.map(serializeVisit),
|
|
234
|
+
})),
|
|
235
|
+
...(page.nextCursor === undefined ? {} : { nextCursor: page.nextCursor }),
|
|
236
|
+
}
|
|
237
|
+
} catch (error) {
|
|
238
|
+
return handleRouteError(error, context.set)
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
query: ActivityConnectionsQuerySchema,
|
|
243
|
+
response: { 200: ActivityConnectionsPageSchema, ...errors },
|
|
244
|
+
detail: {
|
|
245
|
+
summary: "List a user's sign-ins with the visits each opened",
|
|
246
|
+
description: "Newest first, revoked and expired sessions included.",
|
|
247
|
+
tags: [OPENAPI_TAGS.activity.name],
|
|
248
|
+
operationId: "listActivityConnections",
|
|
249
|
+
security: accessTokenSecurityRequirement("listActivityConnections"),
|
|
250
|
+
},
|
|
251
|
+
}
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
return app
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function pageQuery(query: {
|
|
258
|
+
readonly from: string
|
|
259
|
+
readonly to: string
|
|
260
|
+
readonly userId?: string
|
|
261
|
+
readonly limit?: number
|
|
262
|
+
readonly beforeAt?: string
|
|
263
|
+
readonly beforeId?: string
|
|
264
|
+
}) {
|
|
265
|
+
return {
|
|
266
|
+
from: new Date(query.from),
|
|
267
|
+
to: new Date(query.to),
|
|
268
|
+
userId: query.userId,
|
|
269
|
+
limit: query.limit,
|
|
270
|
+
before:
|
|
271
|
+
query.beforeAt !== undefined && query.beforeId !== undefined
|
|
272
|
+
? { at: new Date(query.beforeAt), id: query.beforeId }
|
|
273
|
+
: undefined,
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function serializeVisit(visit: ActivityVisitView) {
|
|
278
|
+
return {
|
|
279
|
+
...visit,
|
|
280
|
+
startedAt: visit.startedAt.toISOString(),
|
|
281
|
+
lastSeenAt: visit.lastSeenAt.toISOString(),
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function serializeTimeline(timeline: ActivityVisitTimeline) {
|
|
286
|
+
return {
|
|
287
|
+
visit: serializeVisit(timeline.visit),
|
|
288
|
+
...(timeline.connection ? { connection: serializeConnection(timeline.connection) } : {}),
|
|
289
|
+
entries: timeline.entries.map(serializeEntry),
|
|
290
|
+
truncated: timeline.truncated,
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function serializeEntry(entry: ActivityTimelineEntry) {
|
|
295
|
+
const at = entry.at.toISOString()
|
|
296
|
+
if (entry.kind !== "agent") {
|
|
297
|
+
return { ...entry, at }
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const { cost, ...run } = entry
|
|
301
|
+
return { ...run, at, ...(cost ? { cost: { ...cost, amounts: [...cost.amounts] } } : {}) }
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function serializeConnection<T extends ActivityConnection>(connection: T) {
|
|
305
|
+
return {
|
|
306
|
+
...connection,
|
|
307
|
+
createdAt: connection.createdAt.toISOString(),
|
|
308
|
+
...(connection.type === "session" && connection.lastSeenAt
|
|
309
|
+
? { lastSeenAt: connection.lastSeenAt.toISOString() }
|
|
310
|
+
: {}),
|
|
311
|
+
...(connection.revokedAt ? { revokedAt: connection.revokedAt.toISOString() } : {}),
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* A signed-in browser records through its cookie. A native client's bearer session is not a
|
|
317
|
+
* visit; a shared-link session has no caller here and is checked by the runtime.
|
|
318
|
+
*/
|
|
319
|
+
function assertBrowserCapture(context: unknown): void {
|
|
320
|
+
const caller = requestCaller(context)
|
|
321
|
+
if (caller && credentialTransport(caller) !== "cookie") {
|
|
322
|
+
throw new AuthorizationError(
|
|
323
|
+
"activity.capture",
|
|
324
|
+
"[SixbServer] Activity is recorded only through a browser or shared-link session."
|
|
325
|
+
)
|
|
326
|
+
}
|
|
327
|
+
}
|
package/src/routes/agents.ts
CHANGED
|
@@ -285,7 +285,7 @@ async function agentMessageFileContentResponse(
|
|
|
285
285
|
fileRef,
|
|
286
286
|
disposition: parsed.disposition,
|
|
287
287
|
head: options.head,
|
|
288
|
-
|
|
288
|
+
request: context.request,
|
|
289
289
|
})
|
|
290
290
|
if (!response) {
|
|
291
291
|
context.set.status = 404
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { SixbHostView } from "@sixb/core"
|
|
2
|
+
import { parseArtifactAddress } from "@sixb/core/artifacts"
|
|
3
|
+
import {
|
|
4
|
+
ARTIFACT_FRAME_ROUTE_PREFIX,
|
|
5
|
+
FRAME_ASSETS,
|
|
6
|
+
FRAME_REFERENCE_PREFIX,
|
|
7
|
+
injectFrameAssets,
|
|
8
|
+
resolveArtifactFrame,
|
|
9
|
+
rewriteFrameReferences,
|
|
10
|
+
} from "@sixb/core/internal/artifacts/frames"
|
|
11
|
+
import { openFileRef } from "@sixb/core/internal/blob-storage"
|
|
12
|
+
import type { Elysia } from "elysia"
|
|
13
|
+
import { frameContentSecurityPolicy } from "../artifacts/frame"
|
|
14
|
+
import type { ResolvedSixbApiBrowserPolicy } from "../auth/browser-origin"
|
|
15
|
+
import { createFileContentResponse } from "../files/content"
|
|
16
|
+
|
|
17
|
+
interface FrameContext {
|
|
18
|
+
readonly params: { readonly token: string; readonly "*": string }
|
|
19
|
+
readonly request: Request
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Serves a deck's files to its sandboxed frame, under the token a frame link carries: the token
|
|
24
|
+
* is the credential, so the route is public. The entry gets the kit and the runtime, and the kit
|
|
25
|
+
* and runtime are served beside the files. Hidden from OpenAPI: clients receive frame links, they
|
|
26
|
+
* never build them.
|
|
27
|
+
*/
|
|
28
|
+
export function registerArtifactFrameRoutes(
|
|
29
|
+
app: Elysia,
|
|
30
|
+
host: SixbHostView,
|
|
31
|
+
policy: ResolvedSixbApiBrowserPolicy
|
|
32
|
+
) {
|
|
33
|
+
const path = `${ARTIFACT_FRAME_ROUTE_PREFIX}:token/*`
|
|
34
|
+
return app
|
|
35
|
+
.get(path, (context) => frameResponse(host, policy, context), { detail: { hide: true } })
|
|
36
|
+
.head(path, (context) => frameResponse(host, policy, context, { head: true }), {
|
|
37
|
+
detail: { hide: true },
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function frameResponse(
|
|
42
|
+
host: SixbHostView,
|
|
43
|
+
policy: ResolvedSixbApiBrowserPolicy,
|
|
44
|
+
{ params, request }: FrameContext,
|
|
45
|
+
options: { readonly head?: boolean } = {}
|
|
46
|
+
): Promise<Response> {
|
|
47
|
+
const headers = new Headers({
|
|
48
|
+
"content-security-policy": frameContentSecurityPolicy({ policy, request, token: params.token }),
|
|
49
|
+
// The frame's origin is opaque, so its module scripts and fonts arrive with `Origin: null`.
|
|
50
|
+
// Nothing here depends on cookies: the token is the credential.
|
|
51
|
+
"access-control-allow-origin": "*",
|
|
52
|
+
"x-content-type-options": "nosniff",
|
|
53
|
+
"referrer-policy": "no-referrer",
|
|
54
|
+
})
|
|
55
|
+
const notFound = () => {
|
|
56
|
+
headers.set("content-type", "text/plain; charset=utf-8")
|
|
57
|
+
headers.set("cache-control", "no-store")
|
|
58
|
+
return new Response(options.head ? null : "Not found", { status: 404, headers })
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// A frame link opens only in a frame. Opened as a page on the API's origin, its sandbox would
|
|
62
|
+
// still let it show dialogs and open windows that escape the sandbox, under the API's address.
|
|
63
|
+
if (request.headers.get("sec-fetch-dest") === "document") return notFound()
|
|
64
|
+
|
|
65
|
+
const storage = host.storage.artifacts
|
|
66
|
+
if (!storage) return notFound()
|
|
67
|
+
// An unknown or expired token, a deleted version, and one that is no deck all answer one 404.
|
|
68
|
+
const frame = await resolveArtifactFrame({
|
|
69
|
+
projectId: host.id,
|
|
70
|
+
storage,
|
|
71
|
+
token: params.token,
|
|
72
|
+
})
|
|
73
|
+
if (!frame) return notFound()
|
|
74
|
+
let version = frame.version
|
|
75
|
+
|
|
76
|
+
let path = decodePath(params["*"])
|
|
77
|
+
const asset = path === null ? undefined : FRAME_ASSETS[path]
|
|
78
|
+
if (asset) {
|
|
79
|
+
headers.set("content-type", asset.type)
|
|
80
|
+
headers.set("cache-control", "private, max-age=3600")
|
|
81
|
+
return new Response(options.head ? null : asset.body, { headers })
|
|
82
|
+
}
|
|
83
|
+
let lent = false
|
|
84
|
+
if (path?.startsWith(FRAME_REFERENCE_PREFIX)) {
|
|
85
|
+
// A file another artifact lends the deck: only one its frame was issued with, at that version.
|
|
86
|
+
const match = /^([^/@]+)@(\d+)\/(.+)$/.exec(path.slice(FRAME_REFERENCE_PREFIX.length))
|
|
87
|
+
const target = frame.targets.find(
|
|
88
|
+
(candidate) =>
|
|
89
|
+
candidate.artifactId === match?.[1] &&
|
|
90
|
+
candidate.version === Number(match?.[2]) &&
|
|
91
|
+
parseArtifactAddress(candidate.address)?.path === match?.[3]
|
|
92
|
+
)
|
|
93
|
+
const lender = target
|
|
94
|
+
? await storage.getVersion({
|
|
95
|
+
projectId: host.id,
|
|
96
|
+
artifactId: target.artifactId,
|
|
97
|
+
version: target.version,
|
|
98
|
+
})
|
|
99
|
+
: null
|
|
100
|
+
if (!lender || !match) return notFound()
|
|
101
|
+
version = lender
|
|
102
|
+
path = match[3] ?? null
|
|
103
|
+
lent = true
|
|
104
|
+
}
|
|
105
|
+
const file = version.files.find((candidate) => candidate.path === path)
|
|
106
|
+
if (!file) return notFound()
|
|
107
|
+
|
|
108
|
+
if (!lent && file.path === version.entry) {
|
|
109
|
+
const opened = await openFileRef(host.blobStorage, file.file)
|
|
110
|
+
if (!opened) return notFound()
|
|
111
|
+
headers.set("content-type", "text/html; charset=utf-8")
|
|
112
|
+
headers.set("cache-control", "private, no-cache")
|
|
113
|
+
if (options.head) return new Response(null, { headers })
|
|
114
|
+
const text = await new Response(opened.body).text()
|
|
115
|
+
return new Response(injectFrameAssets(rewriteFrameReferences(text, frame.targets)), { headers })
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const response = await createFileContentResponse({
|
|
119
|
+
blobStorage: host.blobStorage,
|
|
120
|
+
fileRef: file.file,
|
|
121
|
+
disposition: "inline",
|
|
122
|
+
head: options.head,
|
|
123
|
+
request,
|
|
124
|
+
})
|
|
125
|
+
if (!response) return notFound()
|
|
126
|
+
// A frame loads its files as the page's parts: inline, under the frame's own policy.
|
|
127
|
+
for (const [name, value] of headers) response.headers.set(name, value)
|
|
128
|
+
response.headers.set("content-disposition", "inline")
|
|
129
|
+
return response
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function decodePath(raw: string | undefined): string | null {
|
|
133
|
+
try {
|
|
134
|
+
return decodeURIComponent(raw ?? "")
|
|
135
|
+
} catch {
|
|
136
|
+
return null
|
|
137
|
+
}
|
|
138
|
+
}
|