@sixb/server 0.1.1 → 0.1.3
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/experience.d.ts +33 -0
- package/dist/auth/experience.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.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3903 -2760
- package/dist/index.js.map +58 -50
- package/dist/openapi/tags.d.ts +15 -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 +12 -11
- 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 +230 -159
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/ai-accounting.d.ts +31 -0
- package/dist/routes/ai-accounting.d.ts.map +1 -0
- package/dist/routes/auth.d.ts +149 -92
- 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 +16 -12
- package/dist/routes/datasets.d.ts.map +1 -1
- package/dist/routes/events.d.ts +9 -9
- package/dist/routes/events.d.ts.map +1 -1
- package/dist/routes/files.d.ts +19 -18
- package/dist/routes/files.d.ts.map +1 -1
- package/dist/routes/links.d.ts +11 -11
- 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 +37 -37
- 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 +28 -38
- 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 +145 -85
- 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 +23 -28
- package/dist/routes/syncs.d.ts.map +1 -1
- package/dist/routes/telemetry.d.ts +9 -9
- 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 +177 -66
- 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 +89 -194
- package/dist/schemas/actions.d.ts.map +1 -1
- package/dist/schemas/agents.d.ts +791 -471
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/ai-accounting.d.ts +2393 -0
- package/dist/schemas/ai-accounting.d.ts.map +1 -0
- 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 +102 -102
- 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 +12 -12
- package/dist/schemas/events.d.ts +40 -40
- package/dist/schemas/links.d.ts +2 -2
- 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 +89 -184
- package/dist/schemas/pipelines.d.ts.map +1 -1
- package/dist/schemas/projections.d.ts +1030 -563
- package/dist/schemas/projections.d.ts.map +1 -1
- package/dist/schemas/rules.d.ts +6 -6
- 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 +1189 -185
- package/dist/schemas/workflows.d.ts.map +1 -1
- package/dist/server.d.ts +11 -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 +5 -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/experience.ts +190 -0
- package/src/auth/guard.ts +11 -11
- package/src/auth/public-routes.ts +20 -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/index.ts +1 -0
- package/src/openapi/tags.ts +13 -1
- package/src/registerRoutes.ts +36 -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 +90 -200
- package/src/routes/ai-accounting.ts +166 -0
- package/src/routes/auth.ts +274 -122
- 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 +44 -42
- 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 +242 -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 +23 -23
- package/src/schemas/ai-accounting.ts +182 -0
- 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 +23 -3
- package/src/schemas/syncs.ts +13 -8
- package/src/schemas/webhook-runs.ts +10 -5
- package/src/schemas/workflows.ts +23 -8
- package/src/server.ts +75 -26
- package/src/utils/http.ts +34 -6
- package/src/utils/ws.ts +10 -5
|
@@ -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
|
}
|