@sixb/server 0.1.1 → 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 +13 -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/index.js +3293 -2704
- package/dist/index.js.map +55 -50
- 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 +84 -84
- 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 +8 -4
- 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 +50 -50
- package/dist/routes/ontology.d.ts.map +1 -1
- package/dist/routes/pipelines.d.ts +24 -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 +20 -25
- 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 +74 -48
- 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 +442 -439
- 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 +142 -142
- 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 +2 -2
- 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 +118 -118
- package/dist/schemas/pipelines.d.ts +95 -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 +65 -108
- 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 +516 -183
- 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 +4 -4
- 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 +26 -36
- package/src/auth/session-cookies.ts +3 -3
- package/src/connectors/http.ts +110 -0
- package/src/openapi/tags.ts +9 -1
- package/src/registerRoutes.ts +34 -23
- package/src/routes/action-runs.ts +39 -39
- package/src/routes/actions.ts +7 -13
- package/src/routes/agent-api-gateway.ts +41 -38
- 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 +22 -30
- package/src/routes/links.ts +31 -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 +226 -248
- 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/pipelines.ts +23 -15
- package/src/schemas/projections.ts +17 -3
- package/src/schemas/syncs.ts +13 -8
- package/src/schemas/webhook-runs.ts +10 -5
- package/src/schemas/workflows.ts +16 -6
- 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,10 +1,9 @@
|
|
|
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,
|
|
@@ -63,25 +62,35 @@ function serializeActionRunDetail(
|
|
|
63
62
|
...serializeActionRunSummary(run),
|
|
64
63
|
params: run.params,
|
|
65
64
|
writeback: run.writeback
|
|
66
|
-
?
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
+
}
|
|
72
76
|
: undefined,
|
|
73
77
|
effects: run.effects
|
|
74
|
-
?
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
+
}
|
|
79
88
|
: undefined,
|
|
80
89
|
})
|
|
81
90
|
}
|
|
82
91
|
|
|
83
92
|
async function actionRunFileContentResponse(
|
|
84
|
-
|
|
93
|
+
host: SixbHostView,
|
|
85
94
|
context: {
|
|
86
95
|
readonly params: { readonly runId: string }
|
|
87
96
|
readonly query: unknown
|
|
@@ -90,40 +99,36 @@ async function actionRunFileContentResponse(
|
|
|
90
99
|
},
|
|
91
100
|
options: { readonly head?: boolean } = {}
|
|
92
101
|
) {
|
|
93
|
-
const
|
|
102
|
+
const sixb = requireRequestSixb(context)
|
|
94
103
|
|
|
95
|
-
const storage =
|
|
104
|
+
const storage = host.storage.actionRuns
|
|
96
105
|
if (!storage) {
|
|
97
106
|
return unconfiguredStorageResponse(context.set, "Action run storage")
|
|
98
107
|
}
|
|
99
108
|
|
|
100
109
|
return createContextualFileContentResponse({
|
|
101
|
-
blobStorage:
|
|
110
|
+
blobStorage: host.blobStorage,
|
|
102
111
|
query: context.query,
|
|
103
112
|
querySchema: ActionRunFileContentQuerySchema,
|
|
104
113
|
request: context.request,
|
|
105
114
|
set: context.set,
|
|
106
115
|
head: options.head,
|
|
107
116
|
resolveRoot: async () => {
|
|
108
|
-
const run = await
|
|
109
|
-
|
|
110
|
-
return null
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return serializeActionRunDetail(run)
|
|
117
|
+
const run = await sixb.actions.runs.getById(context.params.runId)
|
|
118
|
+
return run ? serializeActionRunDetail(run) : null
|
|
114
119
|
},
|
|
115
120
|
})
|
|
116
121
|
}
|
|
117
122
|
|
|
118
|
-
export function registerActionRunRoutes(app: Elysia,
|
|
123
|
+
export function registerActionRunRoutes(app: Elysia, host: SixbHostView) {
|
|
119
124
|
return app
|
|
120
125
|
.get(
|
|
121
126
|
"/api/action-runs",
|
|
122
127
|
async (context) => {
|
|
123
128
|
const { query, set } = context
|
|
124
|
-
const
|
|
129
|
+
const sixb = requireRequestSixb(context)
|
|
125
130
|
try {
|
|
126
|
-
const storage =
|
|
131
|
+
const storage = host.storage.actionRuns
|
|
127
132
|
if (!storage) {
|
|
128
133
|
return unconfiguredStorageResponse(set, "Action run storage")
|
|
129
134
|
}
|
|
@@ -131,14 +136,9 @@ export function registerActionRunRoutes(app: Elysia, sixb: Sixb<readonly Ontolog
|
|
|
131
136
|
const parsed = ActionRunsQuerySchema.parse(query)
|
|
132
137
|
const limit = parseOptionalInt(parsed.limit)
|
|
133
138
|
const offset = parseOptionalInt(parsed.offset)
|
|
134
|
-
const
|
|
135
|
-
const objectTypeIds = authz ? [...authz.grants["view:object"]] : undefined
|
|
136
|
-
const result = await storage.list({
|
|
137
|
-
projectId: sixb.id,
|
|
139
|
+
const result = await sixb.actions.runs.list({
|
|
138
140
|
actionId: parsed.actionId,
|
|
139
|
-
actionIds,
|
|
140
141
|
objectTypeId: parsed.objectTypeId,
|
|
141
|
-
objectTypeIds,
|
|
142
142
|
primaryId: parsed.primaryId,
|
|
143
143
|
statuses: parsed.status ? [parsed.status] : undefined,
|
|
144
144
|
startedAfter: parseDate(parsed.startedAfter),
|
|
@@ -176,15 +176,15 @@ export function registerActionRunRoutes(app: Elysia, sixb: Sixb<readonly Ontolog
|
|
|
176
176
|
"/api/action-runs/:runId",
|
|
177
177
|
async (context) => {
|
|
178
178
|
const { params, set } = context
|
|
179
|
-
const
|
|
179
|
+
const sixb = requireRequestSixb(context)
|
|
180
180
|
try {
|
|
181
|
-
const storage =
|
|
181
|
+
const storage = host.storage.actionRuns
|
|
182
182
|
if (!storage) {
|
|
183
183
|
return unconfiguredStorageResponse(set, "Action run storage")
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
const run = await
|
|
187
|
-
if (!run
|
|
186
|
+
const run = await sixb.actions.runs.getById(params.runId)
|
|
187
|
+
if (!run) {
|
|
188
188
|
set.status = 404
|
|
189
189
|
return { error: "Action run not found" }
|
|
190
190
|
}
|
|
@@ -212,7 +212,7 @@ export function registerActionRunRoutes(app: Elysia, sixb: Sixb<readonly Ontolog
|
|
|
212
212
|
)
|
|
213
213
|
.get(
|
|
214
214
|
"/api/action-runs/:runId/files/content",
|
|
215
|
-
(context) => actionRunFileContentResponse(
|
|
215
|
+
(context) => actionRunFileContentResponse(host, context),
|
|
216
216
|
{
|
|
217
217
|
params: ActionRunIdParamsSchema,
|
|
218
218
|
query: ActionRunFileContentQuerySchema,
|
|
@@ -228,7 +228,7 @@ export function registerActionRunRoutes(app: Elysia, sixb: Sixb<readonly Ontolog
|
|
|
228
228
|
)
|
|
229
229
|
.head(
|
|
230
230
|
"/api/action-runs/:runId/files/content",
|
|
231
|
-
(context) => actionRunFileContentResponse(
|
|
231
|
+
(context) => actionRunFileContentResponse(host, context, { head: true }),
|
|
232
232
|
{
|
|
233
233
|
params: ActionRunIdParamsSchema,
|
|
234
234
|
query: ActionRunFileContentQuerySchema,
|
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,9 +1,11 @@
|
|
|
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"
|
|
@@ -22,12 +24,12 @@ const HOP_BY_HOP_RESPONSE_HEADERS = new Set([
|
|
|
22
24
|
"upgrade",
|
|
23
25
|
])
|
|
24
26
|
|
|
25
|
-
export function registerAgentApiGatewayRoutes(app: Elysia,
|
|
27
|
+
export function registerAgentApiGatewayRoutes(app: Elysia, host: SixbHostView) {
|
|
26
28
|
for (const route of AGENT_API_ROUTES) {
|
|
27
29
|
const path = `${AGENT_API_GATEWAY_PREFIX}/:agentGatewayRunId/:agentGatewayCapability${route.path}`
|
|
28
30
|
const handler = async (context: AgentApiGatewayRouteContext) =>
|
|
29
31
|
handleAgentApiGatewayRequest({
|
|
30
|
-
|
|
32
|
+
host,
|
|
31
33
|
app,
|
|
32
34
|
request: context.request,
|
|
33
35
|
agentRunId: context.params.agentGatewayRunId ?? "",
|
|
@@ -53,7 +55,7 @@ interface AgentApiGatewayRouteContext {
|
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
async function handleAgentApiGatewayRequest(input: {
|
|
56
|
-
readonly
|
|
58
|
+
readonly host: SixbHostView
|
|
57
59
|
readonly app: Elysia
|
|
58
60
|
readonly request: Request
|
|
59
61
|
readonly agentRunId: string
|
|
@@ -68,7 +70,7 @@ async function handleAgentApiGatewayRequest(input: {
|
|
|
68
70
|
)
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
const authState = await resolveAgentRunAuthState(input.
|
|
73
|
+
const authState = await resolveAgentRunAuthState(input.host, {
|
|
72
74
|
runId: input.agentRunId,
|
|
73
75
|
capability: input.capability,
|
|
74
76
|
})
|
|
@@ -115,11 +117,11 @@ async function handleAgentApiGatewayRequest(input: {
|
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
async function resolveAgentRunAuthState(
|
|
118
|
-
|
|
120
|
+
host: SixbHostView,
|
|
119
121
|
input: { readonly runId: string; readonly capability: string }
|
|
120
122
|
) {
|
|
121
|
-
const agentStorage =
|
|
122
|
-
const workflowRuns =
|
|
123
|
+
const agentStorage = host.storage.agents
|
|
124
|
+
const workflowRuns = host.storage.workflowRuns
|
|
123
125
|
if (!agentStorage && !workflowRuns) {
|
|
124
126
|
// 501, not 403: nothing about the caller is being refused — neither storage role
|
|
125
127
|
// that could hold an agent run is configured, so no request can ever succeed here.
|
|
@@ -127,13 +129,13 @@ async function resolveAgentRunAuthState(
|
|
|
127
129
|
}
|
|
128
130
|
|
|
129
131
|
const conversationalRun = await agentStorage?.runs.getById({
|
|
130
|
-
projectId:
|
|
132
|
+
projectId: host.id,
|
|
131
133
|
id: input.runId,
|
|
132
134
|
})
|
|
133
135
|
const workflowRun = conversationalRun
|
|
134
136
|
? null
|
|
135
137
|
: await workflowRuns?.agentNodes.getByNodeRunId({
|
|
136
|
-
projectId:
|
|
138
|
+
projectId: host.id,
|
|
137
139
|
nodeRunId: input.runId,
|
|
138
140
|
})
|
|
139
141
|
const run = conversationalRun ?? workflowRun
|
|
@@ -149,7 +151,7 @@ async function resolveAgentRunAuthState(
|
|
|
149
151
|
!run.execution ||
|
|
150
152
|
run.execution.queueLeaseExpiresAt.getTime() <= Date.now() ||
|
|
151
153
|
!isValidAgentApiGatewayCapability({
|
|
152
|
-
projectId:
|
|
154
|
+
projectId: host.id,
|
|
153
155
|
runId: input.runId,
|
|
154
156
|
executionToken: run.execution.token,
|
|
155
157
|
capability: input.capability,
|
|
@@ -158,47 +160,48 @@ async function resolveAgentRunAuthState(
|
|
|
158
160
|
return jsonError(403, "Agent API gateway capability is not valid for this run.")
|
|
159
161
|
}
|
|
160
162
|
|
|
161
|
-
if (!
|
|
163
|
+
if (!host.auth.isEnabled()) {
|
|
162
164
|
return {
|
|
163
|
-
|
|
164
|
-
scoped: null,
|
|
165
|
+
authorization: { type: "disabled" as const },
|
|
165
166
|
agentExecution,
|
|
166
167
|
...(conversationalRun ? { agentRun: conversationalRun } : {}),
|
|
167
168
|
}
|
|
168
169
|
}
|
|
169
170
|
|
|
170
|
-
|
|
171
|
-
// operator did not configure; a run without an execution principal is a run that
|
|
172
|
-
// cannot prove an identity. Only the first is a 501.
|
|
173
|
-
const auth = sixb.storage.auth
|
|
171
|
+
const auth = host.storage.auth
|
|
174
172
|
if (!auth) {
|
|
175
173
|
return jsonError(501, "Agent API gateway is not configured for authenticated agent access.")
|
|
176
174
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const serviceAccount = await auth.serviceAccounts.getById({
|
|
182
|
-
projectId: sixb.id,
|
|
183
|
-
id: run.executionPrincipal.id,
|
|
175
|
+
const execution = await host.storage.executions.getById({
|
|
176
|
+
projectId: host.id,
|
|
177
|
+
id: run.executionId,
|
|
184
178
|
})
|
|
185
|
-
if (!
|
|
186
|
-
return jsonError(403, "Agent execution
|
|
179
|
+
if (!execution) {
|
|
180
|
+
return jsonError(403, "Agent run execution is not available.")
|
|
187
181
|
}
|
|
188
182
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
+
}
|
|
198
202
|
|
|
199
203
|
return {
|
|
200
|
-
authz,
|
|
201
|
-
scoped: sixb.as(authz),
|
|
204
|
+
authorization: { type: "principal" as const, context: authz },
|
|
202
205
|
agentExecution,
|
|
203
206
|
...(conversationalRun ? { agentRun: conversationalRun } : {}),
|
|
204
207
|
}
|