@sixb/server 0.1.0 → 0.1.2
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 +3 -3
- package/dist/auth/application-access.d.ts +2 -2
- package/dist/auth/application-access.d.ts.map +1 -1
- package/dist/auth/connector-callback-cookie.d.ts +12 -0
- package/dist/auth/connector-callback-cookie.d.ts.map +1 -0
- package/dist/auth/guard.d.ts +3 -3
- package/dist/auth/guard.d.ts.map +1 -1
- package/dist/auth/public-routes.d.ts.map +1 -1
- package/dist/auth/scope.d.ts +21 -27
- package/dist/auth/scope.d.ts.map +1 -1
- package/dist/auth/session-cookies.d.ts +2 -2
- package/dist/auth/session-cookies.d.ts.map +1 -1
- package/dist/connectors/http.d.ts +16 -0
- package/dist/connectors/http.d.ts.map +1 -0
- package/dist/files/content.d.ts +11 -0
- package/dist/files/content.d.ts.map +1 -1
- package/dist/index.js +4164 -3541
- package/dist/index.js.map +57 -52
- package/dist/openapi/tags.d.ts +11 -3
- package/dist/openapi/tags.d.ts.map +1 -1
- package/dist/registerRoutes.d.ts +6 -2
- package/dist/registerRoutes.d.ts.map +1 -1
- package/dist/routes/action-runs.d.ts +21 -31
- package/dist/routes/action-runs.d.ts.map +1 -1
- package/dist/routes/actions.d.ts +9 -8
- package/dist/routes/actions.d.ts.map +1 -1
- package/dist/routes/agent-api-gateway.d.ts +2 -2
- package/dist/routes/agent-api-gateway.d.ts.map +1 -1
- package/dist/routes/agents.d.ts +130 -131
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/auth.d.ts +90 -90
- package/dist/routes/auth.d.ts.map +1 -1
- package/dist/routes/connector-connection-runs.d.ts +794 -0
- package/dist/routes/connector-connection-runs.d.ts.map +1 -0
- package/dist/routes/connector-connections.d.ts +219 -0
- package/dist/routes/connector-connections.d.ts.map +1 -0
- package/dist/routes/connectors.d.ts +10 -4
- package/dist/routes/connectors.d.ts.map +1 -1
- package/dist/routes/datasets.d.ts +15 -9
- package/dist/routes/datasets.d.ts.map +1 -1
- package/dist/routes/events.d.ts +8 -8
- package/dist/routes/events.d.ts.map +1 -1
- package/dist/routes/files.d.ts +11 -10
- package/dist/routes/files.d.ts.map +1 -1
- package/dist/routes/links.d.ts +2 -2
- package/dist/routes/links.d.ts.map +1 -1
- package/dist/routes/logs.d.ts +5 -5
- package/dist/routes/logs.d.ts.map +1 -1
- package/dist/routes/objects.d.ts +34 -34
- package/dist/routes/objects.d.ts.map +1 -1
- package/dist/routes/ontology.d.ts +62 -62
- package/dist/routes/ontology.d.ts.map +1 -1
- package/dist/routes/pipelines.d.ts +28 -34
- package/dist/routes/pipelines.d.ts.map +1 -1
- package/dist/routes/project.d.ts +2 -2
- package/dist/routes/project.d.ts.map +1 -1
- package/dist/routes/projections.d.ts +131 -83
- package/dist/routes/projections.d.ts.map +1 -1
- package/dist/routes/rules.d.ts +6 -6
- package/dist/routes/rules.d.ts.map +1 -1
- package/dist/routes/status.d.ts +2 -2
- package/dist/routes/status.d.ts.map +1 -1
- package/dist/routes/syncs.d.ts +27 -30
- package/dist/routes/syncs.d.ts.map +1 -1
- package/dist/routes/telemetry.d.ts +2 -2
- package/dist/routes/telemetry.d.ts.map +1 -1
- package/dist/routes/webhook-runs.d.ts +9 -9
- package/dist/routes/webhook-runs.d.ts.map +1 -1
- package/dist/routes/webhooks.d.ts +2 -2
- package/dist/routes/webhooks.d.ts.map +1 -1
- package/dist/routes/workflows.d.ts +132 -107
- package/dist/routes/workflows.d.ts.map +1 -1
- package/dist/routes/ws/agents.d.ts +11 -5
- package/dist/routes/ws/agents.d.ts.map +1 -1
- package/dist/routes/ws/events.d.ts +8 -8
- package/dist/routes/ws/events.d.ts.map +1 -1
- package/dist/routes/ws/log-subscription-hub.d.ts +6 -3
- package/dist/routes/ws/log-subscription-hub.d.ts.map +1 -1
- package/dist/routes/ws/logs.d.ts +10 -10
- package/dist/routes/ws/logs.d.ts.map +1 -1
- package/dist/schemas/actions.d.ts +97 -202
- package/dist/schemas/actions.d.ts.map +1 -1
- package/dist/schemas/agents.d.ts +443 -440
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/ai-usage.d.ts +34 -0
- package/dist/schemas/ai-usage.d.ts.map +1 -0
- package/dist/schemas/auth.d.ts +168 -168
- package/dist/schemas/common.d.ts +37 -0
- package/dist/schemas/common.d.ts.map +1 -1
- package/dist/schemas/connectors.d.ts +713 -2
- package/dist/schemas/connectors.d.ts.map +1 -1
- package/dist/schemas/datasets.d.ts +29 -23
- package/dist/schemas/datasets.d.ts.map +1 -1
- package/dist/schemas/event-payloads.d.ts +6 -6
- package/dist/schemas/events.d.ts +34 -34
- package/dist/schemas/logs.d.ts +22 -22
- package/dist/schemas/objects.d.ts +10 -10
- package/dist/schemas/ontology.d.ts +174 -174
- package/dist/schemas/pipelines.d.ts +131 -190
- package/dist/schemas/pipelines.d.ts.map +1 -1
- package/dist/schemas/projections.d.ts +918 -563
- package/dist/schemas/projections.d.ts.map +1 -1
- package/dist/schemas/rules.d.ts +6 -6
- package/dist/schemas/status.d.ts +2 -2
- package/dist/schemas/syncs.d.ts +88 -124
- package/dist/schemas/syncs.d.ts.map +1 -1
- package/dist/schemas/webhook-runs.d.ts +41 -41
- package/dist/schemas/webhook-runs.d.ts.map +1 -1
- package/dist/schemas/workflows.d.ts +792 -406
- package/dist/schemas/workflows.d.ts.map +1 -1
- package/dist/server.d.ts +6 -6
- package/dist/server.d.ts.map +1 -1
- package/dist/utils/http.d.ts +2 -0
- package/dist/utils/http.d.ts.map +1 -1
- package/dist/utils/ws.d.ts +4 -3
- package/dist/utils/ws.d.ts.map +1 -1
- package/package.json +8 -5
- package/src/auth/access-token-boundary.ts +4 -4
- package/src/auth/application-access.ts +8 -9
- package/src/auth/connector-callback-cookie.ts +95 -0
- package/src/auth/guard.ts +11 -11
- package/src/auth/public-routes.ts +13 -0
- package/src/auth/scope.ts +34 -30
- package/src/auth/session-cookies.ts +3 -3
- package/src/connectors/http.ts +110 -0
- package/src/files/content.ts +11 -0
- package/src/openapi/tags.ts +9 -1
- package/src/registerRoutes.ts +34 -23
- package/src/routes/action-runs.ts +49 -42
- package/src/routes/actions.ts +7 -13
- package/src/routes/agent-api-gateway.ts +87 -42
- package/src/routes/agents.ts +89 -200
- package/src/routes/auth.ts +87 -91
- package/src/routes/connector-connection-runs.ts +346 -0
- package/src/routes/connector-connections.ts +135 -0
- package/src/routes/connectors.ts +24 -12
- package/src/routes/datasets.ts +55 -54
- package/src/routes/events.ts +5 -5
- package/src/routes/files.ts +24 -31
- package/src/routes/links.ts +32 -35
- package/src/routes/logs.ts +6 -11
- package/src/routes/objects.ts +51 -114
- package/src/routes/ontology.ts +27 -38
- package/src/routes/pipelines.ts +28 -62
- package/src/routes/project.ts +3 -3
- package/src/routes/projections.ts +26 -38
- package/src/routes/rules.ts +11 -25
- package/src/routes/status.ts +5 -5
- package/src/routes/syncs.ts +19 -45
- package/src/routes/telemetry.ts +18 -29
- package/src/routes/webhook-runs.ts +5 -5
- package/src/routes/webhooks.ts +259 -341
- package/src/routes/workflows.ts +260 -259
- package/src/routes/ws/agents.ts +196 -66
- package/src/routes/ws/events.ts +11 -10
- package/src/routes/ws/log-subscription-hub.ts +6 -12
- package/src/routes/ws/logs.ts +13 -5
- package/src/schemas/actions.ts +58 -25
- package/src/schemas/agents.ts +19 -14
- package/src/schemas/ai-usage.ts +16 -0
- package/src/schemas/common.ts +24 -0
- package/src/schemas/connectors.ts +164 -0
- package/src/schemas/datasets.ts +3 -2
- package/src/schemas/pipelines.ts +24 -40
- package/src/schemas/projections.ts +17 -3
- package/src/schemas/syncs.ts +16 -10
- package/src/schemas/webhook-runs.ts +10 -5
- package/src/schemas/workflows.ts +42 -25
- package/src/server.ts +65 -26
- package/src/utils/http.ts +34 -6
- package/src/utils/ws.ts +10 -5
package/src/registerRoutes.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SixbHostView } from "@sixb/core"
|
|
2
2
|
import type { Elysia } from "elysia"
|
|
3
3
|
import { registerActionRunRoutes } from "./routes/action-runs"
|
|
4
4
|
import { registerActionRoutes } from "./routes/actions"
|
|
5
5
|
import { registerAgentApiGatewayRoutes } from "./routes/agent-api-gateway"
|
|
6
6
|
import { registerAgentRoutes } from "./routes/agents"
|
|
7
|
+
import {
|
|
8
|
+
type ConnectorConnectionRouteOptions,
|
|
9
|
+
registerConnectorConnectionRunRoutes,
|
|
10
|
+
} from "./routes/connector-connection-runs"
|
|
11
|
+
import { registerConnectorConnectionRoutes } from "./routes/connector-connections"
|
|
7
12
|
import { registerConnectorRoutes } from "./routes/connectors"
|
|
8
13
|
import { registerDatasetRoutes } from "./routes/datasets"
|
|
9
14
|
import { registerEventRoutes } from "./routes/events"
|
|
@@ -22,28 +27,34 @@ import { registerTelemetryRoutes } from "./routes/telemetry"
|
|
|
22
27
|
import { registerWebhookRunRoutes } from "./routes/webhook-runs"
|
|
23
28
|
import { registerWorkflowRoutes } from "./routes/workflows"
|
|
24
29
|
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
30
|
+
export interface HttpRouteOptions {
|
|
31
|
+
readonly connectorConnections: ConnectorConnectionRouteOptions
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function registerHttpRoutes(app: Elysia, host: SixbHostView, options: HttpRouteOptions) {
|
|
35
|
+
registerAgentApiGatewayRoutes(app, host)
|
|
36
|
+
registerProjectRoutes(app, host)
|
|
37
|
+
registerStatusRoutes(app, host)
|
|
38
|
+
registerConnectorRoutes(app, host)
|
|
39
|
+
registerConnectorConnectionRoutes(app, host)
|
|
40
|
+
registerConnectorConnectionRunRoutes(app, host, options.connectorConnections)
|
|
41
|
+
registerDatasetRoutes(app, host)
|
|
42
|
+
registerSyncRoutes(app, host)
|
|
43
|
+
registerPipelineRoutes(app, host)
|
|
44
|
+
registerWorkflowRoutes(app, host)
|
|
45
|
+
registerRuleRoutes(app, host)
|
|
46
|
+
registerOntologyRoutes(app, host)
|
|
47
|
+
registerObjectRoutes(app, host)
|
|
48
|
+
registerActionRoutes(app, host)
|
|
49
|
+
registerFileRoutes(app, host)
|
|
50
|
+
registerActionRunRoutes(app, host)
|
|
51
|
+
registerAgentRoutes(app, host)
|
|
52
|
+
registerLinkRoutes(app, host)
|
|
53
|
+
registerTelemetryRoutes(app, host)
|
|
54
|
+
registerEventRoutes(app, host)
|
|
55
|
+
registerLogRoutes(app, host)
|
|
56
|
+
registerProjectionRoutes(app, host)
|
|
57
|
+
registerWebhookRunRoutes(app, host)
|
|
47
58
|
|
|
48
59
|
return app
|
|
49
60
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { canViewActionRun } from "@sixb/core/internal/authorization"
|
|
1
|
+
import type { SixbHostView } from "@sixb/core"
|
|
3
2
|
import type { ActionRunRecord } from "@sixb/core/storage"
|
|
4
3
|
import type { Elysia } from "elysia"
|
|
5
4
|
import { z } from "zod"
|
|
6
5
|
import { bearerSecurityRequirement } from "../auth/access-token-boundary"
|
|
7
|
-
import {
|
|
6
|
+
import { requireRequestSixb } from "../auth/scope"
|
|
8
7
|
import {
|
|
9
8
|
createContextualFileContentResponse,
|
|
10
9
|
fileContentGetResponses,
|
|
11
10
|
fileContentHeadResponses,
|
|
11
|
+
handleFileContentQueryValidationError,
|
|
12
12
|
} from "../files/content"
|
|
13
13
|
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
14
14
|
import {
|
|
@@ -32,7 +32,10 @@ const ActionRunFileContentQuerySchema = FileContentQuerySchema.extend({
|
|
|
32
32
|
path: z
|
|
33
33
|
.string()
|
|
34
34
|
.min(1)
|
|
35
|
-
.regex(
|
|
35
|
+
.regex(
|
|
36
|
+
/^\/(?:params|writeback\/result)(?:\/|$)/,
|
|
37
|
+
"Action run file content paths must start with /params/ or /writeback/result/"
|
|
38
|
+
),
|
|
36
39
|
})
|
|
37
40
|
|
|
38
41
|
function serializeActionRunSummary(
|
|
@@ -59,25 +62,35 @@ function serializeActionRunDetail(
|
|
|
59
62
|
...serializeActionRunSummary(run),
|
|
60
63
|
params: run.params,
|
|
61
64
|
writeback: run.writeback
|
|
62
|
-
?
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
? run.writeback.status === "succeeded"
|
|
66
|
+
? {
|
|
67
|
+
status: "succeeded",
|
|
68
|
+
completedAt: toIsoString(run.writeback.completedAt),
|
|
69
|
+
result: run.writeback.result,
|
|
70
|
+
}
|
|
71
|
+
: {
|
|
72
|
+
status: "failed",
|
|
73
|
+
completedAt: toIsoString(run.writeback.completedAt),
|
|
74
|
+
error: run.writeback.error,
|
|
75
|
+
}
|
|
68
76
|
: undefined,
|
|
69
77
|
effects: run.effects
|
|
70
|
-
?
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
? run.effects.status === "succeeded"
|
|
79
|
+
? {
|
|
80
|
+
status: "succeeded",
|
|
81
|
+
completedAt: toIsoString(run.effects.completedAt),
|
|
82
|
+
}
|
|
83
|
+
: {
|
|
84
|
+
status: "failed",
|
|
85
|
+
completedAt: toIsoString(run.effects.completedAt),
|
|
86
|
+
error: run.effects.error,
|
|
87
|
+
}
|
|
75
88
|
: undefined,
|
|
76
89
|
})
|
|
77
90
|
}
|
|
78
91
|
|
|
79
92
|
async function actionRunFileContentResponse(
|
|
80
|
-
|
|
93
|
+
host: SixbHostView,
|
|
81
94
|
context: {
|
|
82
95
|
readonly params: { readonly runId: string }
|
|
83
96
|
readonly query: unknown
|
|
@@ -86,40 +99,36 @@ async function actionRunFileContentResponse(
|
|
|
86
99
|
},
|
|
87
100
|
options: { readonly head?: boolean } = {}
|
|
88
101
|
) {
|
|
89
|
-
const
|
|
102
|
+
const sixb = requireRequestSixb(context)
|
|
90
103
|
|
|
91
|
-
const storage =
|
|
104
|
+
const storage = host.storage.actionRuns
|
|
92
105
|
if (!storage) {
|
|
93
106
|
return unconfiguredStorageResponse(context.set, "Action run storage")
|
|
94
107
|
}
|
|
95
108
|
|
|
96
109
|
return createContextualFileContentResponse({
|
|
97
|
-
blobStorage:
|
|
110
|
+
blobStorage: host.blobStorage,
|
|
98
111
|
query: context.query,
|
|
99
112
|
querySchema: ActionRunFileContentQuerySchema,
|
|
100
113
|
request: context.request,
|
|
101
114
|
set: context.set,
|
|
102
115
|
head: options.head,
|
|
103
116
|
resolveRoot: async () => {
|
|
104
|
-
const run = await
|
|
105
|
-
|
|
106
|
-
return null
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return serializeActionRunDetail(run)
|
|
117
|
+
const run = await sixb.actions.runs.getById(context.params.runId)
|
|
118
|
+
return run ? serializeActionRunDetail(run) : null
|
|
110
119
|
},
|
|
111
120
|
})
|
|
112
121
|
}
|
|
113
122
|
|
|
114
|
-
export function registerActionRunRoutes(app: Elysia,
|
|
123
|
+
export function registerActionRunRoutes(app: Elysia, host: SixbHostView) {
|
|
115
124
|
return app
|
|
116
125
|
.get(
|
|
117
126
|
"/api/action-runs",
|
|
118
127
|
async (context) => {
|
|
119
128
|
const { query, set } = context
|
|
120
|
-
const
|
|
129
|
+
const sixb = requireRequestSixb(context)
|
|
121
130
|
try {
|
|
122
|
-
const storage =
|
|
131
|
+
const storage = host.storage.actionRuns
|
|
123
132
|
if (!storage) {
|
|
124
133
|
return unconfiguredStorageResponse(set, "Action run storage")
|
|
125
134
|
}
|
|
@@ -127,14 +136,9 @@ export function registerActionRunRoutes(app: Elysia, sixb: Sixb<readonly Ontolog
|
|
|
127
136
|
const parsed = ActionRunsQuerySchema.parse(query)
|
|
128
137
|
const limit = parseOptionalInt(parsed.limit)
|
|
129
138
|
const offset = parseOptionalInt(parsed.offset)
|
|
130
|
-
const
|
|
131
|
-
const objectTypeIds = authz ? [...authz.grants["view:object"]] : undefined
|
|
132
|
-
const result = await storage.list({
|
|
133
|
-
projectId: sixb.id,
|
|
139
|
+
const result = await sixb.actions.runs.list({
|
|
134
140
|
actionId: parsed.actionId,
|
|
135
|
-
actionIds,
|
|
136
141
|
objectTypeId: parsed.objectTypeId,
|
|
137
|
-
objectTypeIds,
|
|
138
142
|
primaryId: parsed.primaryId,
|
|
139
143
|
statuses: parsed.status ? [parsed.status] : undefined,
|
|
140
144
|
startedAfter: parseDate(parsed.startedAfter),
|
|
@@ -164,6 +168,7 @@ export function registerActionRunRoutes(app: Elysia, sixb: Sixb<readonly Ontolog
|
|
|
164
168
|
summary: "List action run history",
|
|
165
169
|
tags: [OPENAPI_TAGS.actionRuns.name],
|
|
166
170
|
operationId: "listActionRuns",
|
|
171
|
+
security: bearerSecurityRequirement("listActionRuns"),
|
|
167
172
|
},
|
|
168
173
|
}
|
|
169
174
|
)
|
|
@@ -171,15 +176,15 @@ export function registerActionRunRoutes(app: Elysia, sixb: Sixb<readonly Ontolog
|
|
|
171
176
|
"/api/action-runs/:runId",
|
|
172
177
|
async (context) => {
|
|
173
178
|
const { params, set } = context
|
|
174
|
-
const
|
|
179
|
+
const sixb = requireRequestSixb(context)
|
|
175
180
|
try {
|
|
176
|
-
const storage =
|
|
181
|
+
const storage = host.storage.actionRuns
|
|
177
182
|
if (!storage) {
|
|
178
183
|
return unconfiguredStorageResponse(set, "Action run storage")
|
|
179
184
|
}
|
|
180
185
|
|
|
181
|
-
const run = await
|
|
182
|
-
if (!run
|
|
186
|
+
const run = await sixb.actions.runs.getById(params.runId)
|
|
187
|
+
if (!run) {
|
|
183
188
|
set.status = 404
|
|
184
189
|
return { error: "Action run not found" }
|
|
185
190
|
}
|
|
@@ -207,10 +212,11 @@ export function registerActionRunRoutes(app: Elysia, sixb: Sixb<readonly Ontolog
|
|
|
207
212
|
)
|
|
208
213
|
.get(
|
|
209
214
|
"/api/action-runs/:runId/files/content",
|
|
210
|
-
(context) => actionRunFileContentResponse(
|
|
215
|
+
(context) => actionRunFileContentResponse(host, context),
|
|
211
216
|
{
|
|
212
217
|
params: ActionRunIdParamsSchema,
|
|
213
|
-
query:
|
|
218
|
+
query: ActionRunFileContentQuerySchema,
|
|
219
|
+
error: handleFileContentQueryValidationError,
|
|
214
220
|
detail: {
|
|
215
221
|
summary: "Get action run file content",
|
|
216
222
|
tags: ["Actions"],
|
|
@@ -222,10 +228,11 @@ export function registerActionRunRoutes(app: Elysia, sixb: Sixb<readonly Ontolog
|
|
|
222
228
|
)
|
|
223
229
|
.head(
|
|
224
230
|
"/api/action-runs/:runId/files/content",
|
|
225
|
-
(context) => actionRunFileContentResponse(
|
|
231
|
+
(context) => actionRunFileContentResponse(host, context, { head: true }),
|
|
226
232
|
{
|
|
227
233
|
params: ActionRunIdParamsSchema,
|
|
228
|
-
query:
|
|
234
|
+
query: ActionRunFileContentQuerySchema,
|
|
235
|
+
error: handleFileContentQueryValidationError,
|
|
229
236
|
detail: {
|
|
230
237
|
summary: "Head action run file content",
|
|
231
238
|
tags: ["Actions"],
|
package/src/routes/actions.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ActionDefinition,
|
|
1
|
+
import type { ActionDefinition, SixbHostView } from "@sixb/core"
|
|
2
2
|
import type { Elysia } from "elysia"
|
|
3
3
|
import { bearerSecurityRequirement } from "../auth/access-token-boundary"
|
|
4
|
-
import {
|
|
4
|
+
import { requireRequestSixb } from "../auth/scope"
|
|
5
5
|
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
6
6
|
import {
|
|
7
7
|
ActionCatalogItemSchema,
|
|
@@ -38,13 +38,12 @@ function serializeAction(
|
|
|
38
38
|
})
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export function registerActionRoutes(app: Elysia,
|
|
41
|
+
export function registerActionRoutes(app: Elysia, _host: SixbHostView) {
|
|
42
42
|
return app
|
|
43
43
|
.get(
|
|
44
44
|
"/api/actions",
|
|
45
45
|
async (context) => {
|
|
46
|
-
const
|
|
47
|
-
const actions = scoped ? scoped.listActions() : sixb.listActions()
|
|
46
|
+
const actions = requireRequestSixb(context).actions.list()
|
|
48
47
|
return actions.map(serializeAction)
|
|
49
48
|
},
|
|
50
49
|
{
|
|
@@ -61,10 +60,7 @@ export function registerActionRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
|
|
|
61
60
|
"/api/actions/:actionId",
|
|
62
61
|
async (context) => {
|
|
63
62
|
const { params, set } = context
|
|
64
|
-
const
|
|
65
|
-
const action = scoped
|
|
66
|
-
? scoped.getActionById(params.actionId)
|
|
67
|
-
: sixb.getActionById(params.actionId)
|
|
63
|
+
const action = requireRequestSixb(context).actions.getById(params.actionId)
|
|
68
64
|
if (!action) {
|
|
69
65
|
set.status = 404
|
|
70
66
|
return { error: "Action not found" }
|
|
@@ -87,7 +83,7 @@ export function registerActionRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
|
|
|
87
83
|
"/api/actions/:actionId",
|
|
88
84
|
async (context) => {
|
|
89
85
|
const { params, body, set } = context
|
|
90
|
-
const
|
|
86
|
+
const sixb = requireRequestSixb(context)
|
|
91
87
|
try {
|
|
92
88
|
const parsedBody = RequestActionBodySchema.parse(body)
|
|
93
89
|
const input = {
|
|
@@ -96,9 +92,7 @@ export function registerActionRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
|
|
|
96
92
|
params: parsedBody.params,
|
|
97
93
|
runId: parsedBody.runId,
|
|
98
94
|
}
|
|
99
|
-
const result =
|
|
100
|
-
? await scoped.requestAction(input)
|
|
101
|
-
: await sixb.actions.request(input)
|
|
95
|
+
const result = await sixb.actions.request(input)
|
|
102
96
|
|
|
103
97
|
set.status = 202
|
|
104
98
|
return RequestActionResponseSchema.parse(result)
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { AuthorizationContext, SixbHostView } from "@sixb/core"
|
|
2
|
+
import { assertAgentExecutionRecord } from "@sixb/core/internal/agent-execution"
|
|
2
3
|
import {
|
|
3
4
|
AGENT_API_GATEWAY_PREFIX,
|
|
4
5
|
AGENT_API_ROUTES,
|
|
5
6
|
isAllowedAgentApiRequest,
|
|
6
7
|
isValidAgentApiGatewayCapability,
|
|
8
|
+
resolveAgentExecutionAuthorization,
|
|
7
9
|
} from "@sixb/core/internal/agents"
|
|
8
10
|
import { normalizeRoutePath, pathSegmentsFor } from "@sixb/core/internal/http"
|
|
9
11
|
import type { Elysia } from "elysia"
|
|
10
12
|
import { registerInternalRequestAuthState } from "../auth/scope"
|
|
13
|
+
import { DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES } from "./files"
|
|
11
14
|
|
|
12
15
|
const MAX_AGENT_API_BODY_BYTES = 1_000_000
|
|
13
16
|
const HOP_BY_HOP_RESPONSE_HEADERS = new Set([
|
|
@@ -21,12 +24,12 @@ const HOP_BY_HOP_RESPONSE_HEADERS = new Set([
|
|
|
21
24
|
"upgrade",
|
|
22
25
|
])
|
|
23
26
|
|
|
24
|
-
export function registerAgentApiGatewayRoutes(app: Elysia,
|
|
27
|
+
export function registerAgentApiGatewayRoutes(app: Elysia, host: SixbHostView) {
|
|
25
28
|
for (const route of AGENT_API_ROUTES) {
|
|
26
29
|
const path = `${AGENT_API_GATEWAY_PREFIX}/:agentGatewayRunId/:agentGatewayCapability${route.path}`
|
|
27
30
|
const handler = async (context: AgentApiGatewayRouteContext) =>
|
|
28
31
|
handleAgentApiGatewayRequest({
|
|
29
|
-
|
|
32
|
+
host,
|
|
30
33
|
app,
|
|
31
34
|
request: context.request,
|
|
32
35
|
agentRunId: context.params.agentGatewayRunId ?? "",
|
|
@@ -52,7 +55,7 @@ interface AgentApiGatewayRouteContext {
|
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
async function handleAgentApiGatewayRequest(input: {
|
|
55
|
-
readonly
|
|
58
|
+
readonly host: SixbHostView
|
|
56
59
|
readonly app: Elysia
|
|
57
60
|
readonly request: Request
|
|
58
61
|
readonly agentRunId: string
|
|
@@ -67,17 +70,29 @@ async function handleAgentApiGatewayRequest(input: {
|
|
|
67
70
|
)
|
|
68
71
|
}
|
|
69
72
|
|
|
70
|
-
const authState = await resolveAgentRunAuthState(input.
|
|
73
|
+
const authState = await resolveAgentRunAuthState(input.host, {
|
|
71
74
|
runId: input.agentRunId,
|
|
72
75
|
capability: input.capability,
|
|
73
76
|
})
|
|
74
77
|
if (authState instanceof Response) {
|
|
75
78
|
return authState
|
|
76
79
|
}
|
|
80
|
+
if (
|
|
81
|
+
authState.agentExecution.kind === "workflow" &&
|
|
82
|
+
input.request.method === "POST" &&
|
|
83
|
+
matchesWorkflowRunStart(upstreamPath)
|
|
84
|
+
) {
|
|
85
|
+
return jsonError(409, "Workflow agent nodes cannot start another workflow run.")
|
|
86
|
+
}
|
|
77
87
|
|
|
78
88
|
let body: ArrayBuffer | undefined
|
|
79
89
|
try {
|
|
80
|
-
body = await readRequestBody(
|
|
90
|
+
body = await readRequestBody(
|
|
91
|
+
input.request,
|
|
92
|
+
isSimpleFileUpload(input.request.method, upstreamPath)
|
|
93
|
+
? DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES
|
|
94
|
+
: MAX_AGENT_API_BODY_BYTES
|
|
95
|
+
)
|
|
81
96
|
} catch (error) {
|
|
82
97
|
if (error instanceof PayloadTooLargeError) {
|
|
83
98
|
return jsonError(413, error.message)
|
|
@@ -102,11 +117,11 @@ async function handleAgentApiGatewayRequest(input: {
|
|
|
102
117
|
}
|
|
103
118
|
|
|
104
119
|
async function resolveAgentRunAuthState(
|
|
105
|
-
|
|
120
|
+
host: SixbHostView,
|
|
106
121
|
input: { readonly runId: string; readonly capability: string }
|
|
107
122
|
) {
|
|
108
|
-
const agentStorage =
|
|
109
|
-
const workflowRuns =
|
|
123
|
+
const agentStorage = host.storage.agents
|
|
124
|
+
const workflowRuns = host.storage.workflowRuns
|
|
110
125
|
if (!agentStorage && !workflowRuns) {
|
|
111
126
|
// 501, not 403: nothing about the caller is being refused — neither storage role
|
|
112
127
|
// that could hold an agent run is configured, so no request can ever succeed here.
|
|
@@ -114,23 +129,29 @@ async function resolveAgentRunAuthState(
|
|
|
114
129
|
}
|
|
115
130
|
|
|
116
131
|
const conversationalRun = await agentStorage?.runs.getById({
|
|
117
|
-
projectId:
|
|
132
|
+
projectId: host.id,
|
|
118
133
|
id: input.runId,
|
|
119
134
|
})
|
|
120
135
|
const workflowRun = conversationalRun
|
|
121
136
|
? null
|
|
122
137
|
: await workflowRuns?.agentNodes.getByNodeRunId({
|
|
123
|
-
projectId:
|
|
138
|
+
projectId: host.id,
|
|
124
139
|
nodeRunId: input.runId,
|
|
125
140
|
})
|
|
126
141
|
const run = conversationalRun ?? workflowRun
|
|
142
|
+
const agentExecution = conversationalRun
|
|
143
|
+
? ({ kind: "conversation", runId: conversationalRun.id } as const)
|
|
144
|
+
: workflowRun
|
|
145
|
+
? ({ kind: "workflow", nodeRunId: workflowRun.nodeRunId } as const)
|
|
146
|
+
: null
|
|
127
147
|
if (
|
|
128
148
|
!run ||
|
|
149
|
+
!agentExecution ||
|
|
129
150
|
run.status !== "running" ||
|
|
130
151
|
!run.execution ||
|
|
131
152
|
run.execution.queueLeaseExpiresAt.getTime() <= Date.now() ||
|
|
132
153
|
!isValidAgentApiGatewayCapability({
|
|
133
|
-
projectId:
|
|
154
|
+
projectId: host.id,
|
|
134
155
|
runId: input.runId,
|
|
135
156
|
executionToken: run.execution.token,
|
|
136
157
|
capability: input.capability,
|
|
@@ -139,46 +160,49 @@ async function resolveAgentRunAuthState(
|
|
|
139
160
|
return jsonError(403, "Agent API gateway capability is not valid for this run.")
|
|
140
161
|
}
|
|
141
162
|
|
|
142
|
-
if (!
|
|
163
|
+
if (!host.auth.isEnabled()) {
|
|
143
164
|
return {
|
|
144
|
-
|
|
145
|
-
|
|
165
|
+
authorization: { type: "disabled" as const },
|
|
166
|
+
agentExecution,
|
|
146
167
|
...(conversationalRun ? { agentRun: conversationalRun } : {}),
|
|
147
168
|
}
|
|
148
169
|
}
|
|
149
170
|
|
|
150
|
-
|
|
151
|
-
// operator did not configure; a run without an execution principal is a run that
|
|
152
|
-
// cannot prove an identity. Only the first is a 501.
|
|
153
|
-
const auth = sixb.storage.auth
|
|
171
|
+
const auth = host.storage.auth
|
|
154
172
|
if (!auth) {
|
|
155
173
|
return jsonError(501, "Agent API gateway is not configured for authenticated agent access.")
|
|
156
174
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const serviceAccount = await auth.serviceAccounts.getById({
|
|
162
|
-
projectId: sixb.id,
|
|
163
|
-
id: run.executionPrincipal.id,
|
|
175
|
+
const execution = await host.storage.executions.getById({
|
|
176
|
+
projectId: host.id,
|
|
177
|
+
id: run.executionId,
|
|
164
178
|
})
|
|
165
|
-
if (!
|
|
166
|
-
return jsonError(403, "Agent execution
|
|
179
|
+
if (!execution) {
|
|
180
|
+
return jsonError(403, "Agent run execution is not available.")
|
|
167
181
|
}
|
|
168
182
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
183
|
+
let authz: AuthorizationContext
|
|
184
|
+
try {
|
|
185
|
+
const resolved = await resolveAgentExecutionAuthorization({
|
|
186
|
+
auth,
|
|
187
|
+
projectId: host.id,
|
|
188
|
+
agentId: run.agentId,
|
|
189
|
+
authorizationRef: execution.authorizationRef,
|
|
190
|
+
security: host.definitions.security,
|
|
191
|
+
})
|
|
192
|
+
assertAgentExecutionRecord({
|
|
193
|
+
execution,
|
|
194
|
+
agentId: run.agentId,
|
|
195
|
+
runId: input.runId,
|
|
196
|
+
authorization: resolved.context,
|
|
197
|
+
})
|
|
198
|
+
authz = resolved.context
|
|
199
|
+
} catch {
|
|
200
|
+
return jsonError(403, "Agent run execution authority is not valid.")
|
|
201
|
+
}
|
|
178
202
|
|
|
179
203
|
return {
|
|
180
|
-
authz,
|
|
181
|
-
|
|
204
|
+
authorization: { type: "principal" as const, context: authz },
|
|
205
|
+
agentExecution,
|
|
182
206
|
...(conversationalRun ? { agentRun: conversationalRun } : {}),
|
|
183
207
|
}
|
|
184
208
|
}
|
|
@@ -220,7 +244,10 @@ function copyHeader(source: Headers, target: Headers, name: string): void {
|
|
|
220
244
|
}
|
|
221
245
|
}
|
|
222
246
|
|
|
223
|
-
async function readRequestBody(
|
|
247
|
+
async function readRequestBody(
|
|
248
|
+
request: Request,
|
|
249
|
+
maxBytes: number
|
|
250
|
+
): Promise<ArrayBuffer | undefined> {
|
|
224
251
|
if (!request.body || request.method === "GET" || request.method === "HEAD") {
|
|
225
252
|
return undefined
|
|
226
253
|
}
|
|
@@ -233,8 +260,12 @@ async function readRequestBody(request: Request): Promise<ArrayBuffer | undefine
|
|
|
233
260
|
const { done, value } = await reader.read()
|
|
234
261
|
if (done) break
|
|
235
262
|
total += value.byteLength
|
|
236
|
-
if (total >
|
|
237
|
-
throw new PayloadTooLargeError(
|
|
263
|
+
if (total > maxBytes) {
|
|
264
|
+
throw new PayloadTooLargeError(
|
|
265
|
+
maxBytes === MAX_AGENT_API_BODY_BYTES
|
|
266
|
+
? "Agent API gateway request body exceeds 1MB."
|
|
267
|
+
: `Agent API gateway file upload request body exceeds the ${maxBytes} byte limit.`
|
|
268
|
+
)
|
|
238
269
|
}
|
|
239
270
|
chunks.push(value)
|
|
240
271
|
}
|
|
@@ -242,6 +273,20 @@ async function readRequestBody(request: Request): Promise<ArrayBuffer | undefine
|
|
|
242
273
|
return concatChunks(chunks, total)
|
|
243
274
|
}
|
|
244
275
|
|
|
276
|
+
function isSimpleFileUpload(method: string, pathname: string): boolean {
|
|
277
|
+
return method === "POST" && normalizeRoutePath(pathname) === "/api/files"
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function matchesWorkflowRunStart(pathname: string): boolean {
|
|
281
|
+
const segments = pathSegmentsFor(pathname)
|
|
282
|
+
return (
|
|
283
|
+
segments.length === 4 &&
|
|
284
|
+
segments[0] === "api" &&
|
|
285
|
+
segments[1] === "workflows" &&
|
|
286
|
+
segments[3] === "runs"
|
|
287
|
+
)
|
|
288
|
+
}
|
|
289
|
+
|
|
245
290
|
function concatChunks(chunks: readonly Uint8Array[], total: number): ArrayBuffer {
|
|
246
291
|
const buffer = new ArrayBuffer(total)
|
|
247
292
|
const result = new Uint8Array(buffer)
|