@sixb/server 0.1.5 → 0.1.7
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/dist/auth/public-routes.d.ts.map +1 -1
- package/dist/auth/scope.d.ts +6 -2
- package/dist/auth/scope.d.ts.map +1 -1
- package/dist/files/content.d.ts +8 -0
- package/dist/files/content.d.ts.map +1 -1
- package/dist/index.js +2507 -1573
- package/dist/index.js.map +22 -20
- package/dist/models/display.d.ts +22 -0
- package/dist/models/display.d.ts.map +1 -0
- package/dist/routes/action-runs.d.ts +2 -0
- package/dist/routes/action-runs.d.ts.map +1 -1
- package/dist/routes/actions.d.ts +1 -0
- package/dist/routes/actions.d.ts.map +1 -1
- package/dist/routes/agent-api-gateway.d.ts.map +1 -1
- package/dist/routes/agents.d.ts +99 -89
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/ai-accounting.d.ts.map +1 -1
- package/dist/routes/auth.d.ts +139 -15
- package/dist/routes/auth.d.ts.map +1 -1
- package/dist/routes/events.d.ts +3 -3
- package/dist/routes/files.d.ts +1 -0
- package/dist/routes/files.d.ts.map +1 -1
- package/dist/routes/models.d.ts +18 -1
- package/dist/routes/models.d.ts.map +1 -1
- package/dist/routes/objects.d.ts +3 -1
- package/dist/routes/objects.d.ts.map +1 -1
- package/dist/routes/pipelines.d.ts +2 -1
- package/dist/routes/pipelines.d.ts.map +1 -1
- package/dist/routes/rules.d.ts +1 -1
- package/dist/routes/syncs.d.ts +1 -0
- package/dist/routes/syncs.d.ts.map +1 -1
- package/dist/routes/workflows.d.ts +57 -54
- package/dist/routes/workflows.d.ts.map +1 -1
- package/dist/routes/ws/logs.d.ts +4 -4
- package/dist/schemas/agents.d.ts +378 -215
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/ai-accounting.d.ts +1847 -295
- package/dist/schemas/ai-accounting.d.ts.map +1 -1
- package/dist/schemas/ai-limits.d.ts +2210 -0
- package/dist/schemas/ai-limits.d.ts.map +1 -0
- package/dist/schemas/auth.d.ts +202 -72
- package/dist/schemas/auth.d.ts.map +1 -1
- package/dist/schemas/events.d.ts +6 -6
- package/dist/schemas/files.d.ts +3 -0
- package/dist/schemas/files.d.ts.map +1 -1
- package/dist/schemas/models.d.ts +214 -14
- package/dist/schemas/models.d.ts.map +1 -1
- package/dist/schemas/objects.d.ts +4 -4
- package/dist/schemas/pipelines.d.ts +6 -6
- package/dist/schemas/rules.d.ts +6 -6
- package/dist/schemas/workflows.d.ts +196 -206
- package/dist/schemas/workflows.d.ts.map +1 -1
- package/dist/utils/http.d.ts +8 -4
- package/dist/utils/http.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/auth/public-routes.ts +18 -0
- package/src/auth/scope.ts +3 -2
- package/src/files/content.ts +39 -6
- package/src/models/display.ts +91 -0
- package/src/routes/agent-api-gateway.ts +137 -38
- package/src/routes/agents.ts +58 -83
- package/src/routes/ai-accounting.ts +414 -23
- package/src/routes/auth.ts +297 -2
- package/src/routes/models.ts +12 -4
- package/src/routes/workflows.ts +3 -5
- package/src/routes/ws/agents.ts +17 -6
- package/src/schemas/agents.ts +40 -49
- package/src/schemas/ai-accounting.ts +88 -19
- package/src/schemas/ai-limits.ts +116 -0
- package/src/schemas/auth.ts +39 -0
- package/src/schemas/files.ts +1 -0
- package/src/schemas/models.ts +33 -5
- package/src/schemas/workflows.ts +0 -2
- package/src/utils/http.ts +33 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflows.d.ts","sourceRoot":"","sources":["../../src/schemas/workflows.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAGjB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAMvB,eAAO,MAAM,wBAAwB,+GAA4B,CAAA;AAMjE,eAAO,MAAM,oBAAoB;;;;;;EAE/B,CAAA;AAEF,eAAO,MAAM,uBAAuB;;;;;;EAElC,CAAA;AAEF,eA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEnD,CAAA;AAEF,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;;;EAK3C,CAAA"}
|
package/dist/utils/http.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { type SixbErrorCode } from "@sixb/core";
|
|
1
|
+
import { type ReadonlyJsonValue, type SixbErrorCode } from "@sixb/core";
|
|
2
|
+
interface RouteResponseSet {
|
|
3
|
+
status?: number | string;
|
|
4
|
+
headers?: unknown;
|
|
5
|
+
}
|
|
2
6
|
export declare function toIsoString(value: Date): string;
|
|
3
7
|
export declare function parseDate(value: string | undefined): Date | undefined;
|
|
4
8
|
export declare function parseOptionalInt(value: string | undefined): number | undefined;
|
|
@@ -16,10 +20,10 @@ export declare function unconfiguredStorageResponse(set: {
|
|
|
16
20
|
}, role: string): {
|
|
17
21
|
error: string;
|
|
18
22
|
};
|
|
19
|
-
export declare function handleRouteError(error: unknown, set: {
|
|
20
|
-
status?: number | string;
|
|
21
|
-
}): {
|
|
23
|
+
export declare function handleRouteError(error: unknown, set: RouteResponseSet): {
|
|
22
24
|
error: string;
|
|
23
25
|
code?: SixbErrorCode;
|
|
26
|
+
details?: ReadonlyJsonValue;
|
|
24
27
|
};
|
|
28
|
+
export {};
|
|
25
29
|
//# sourceMappingURL=http.d.ts.map
|
package/dist/utils/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/utils/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/utils/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,iBAAiB,EACtB,KAAK,aAAa,EACnB,MAAM,YAAY,CAAA;AA6BnB,UAAU,gBAAgB;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,CAE/C;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,CAWrE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAW9E;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CACzC,GAAG,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACjC,IAAI,EAAE,MAAM,GACX;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAGnB;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,gBAAgB,GACpB;IACD,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,aAAa,CAAA;IACpB,OAAO,CAAC,EAAE,iBAAiB,CAAA;CAC5B,CA6CA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sixb/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "HTTP and WebSocket API server for Sixb",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sixb",
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
"zod-to-json-schema": "^3.24.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@sixb/core": "0.1.
|
|
40
|
+
"@sixb/core": "0.1.7"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@sixb/auth-magic-link": "0.1.
|
|
44
|
-
"@sixb/auth-oidc": "0.1.
|
|
45
|
-
"@sixb/core": "0.1.
|
|
46
|
-
"@sixb/sqlite": "0.1.
|
|
43
|
+
"@sixb/auth-magic-link": "0.1.3",
|
|
44
|
+
"@sixb/auth-oidc": "0.1.2",
|
|
45
|
+
"@sixb/core": "0.1.7",
|
|
46
|
+
"@sixb/sqlite": "0.1.7",
|
|
47
47
|
"@types/bun": "latest",
|
|
48
48
|
"typescript": "^5.7.0"
|
|
49
49
|
},
|
|
@@ -26,6 +26,10 @@ export function classifyRoute(request: Request): RouteAccess {
|
|
|
26
26
|
return { kind: "api", csrfProtected: !isCsrfExemptMethod(request.method) }
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
if (pathname === "/auth/device") {
|
|
30
|
+
return { kind: "html", csrfProtected: !isCsrfExemptMethod(request.method) }
|
|
31
|
+
}
|
|
32
|
+
|
|
29
33
|
if (pathname === "/docs" || pathname.startsWith("/docs/")) {
|
|
30
34
|
return { kind: "html", csrfProtected: !isCsrfExemptMethod(request.method) }
|
|
31
35
|
}
|
|
@@ -72,6 +76,20 @@ export function isPublicRoute(pathname: string, method: string): boolean {
|
|
|
72
76
|
return true
|
|
73
77
|
}
|
|
74
78
|
|
|
79
|
+
if (
|
|
80
|
+
(pathname === "/api/auth/device-authorizations" ||
|
|
81
|
+
pathname === "/api/auth/device-authorizations/token") &&
|
|
82
|
+
normalizedMethod === "POST"
|
|
83
|
+
) {
|
|
84
|
+
return true
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Native HTML forms cannot set the CSRF header. The handler authenticates the
|
|
88
|
+
// browser session and verifies the submitted token against the CSRF cookie.
|
|
89
|
+
if (pathname === "/auth/device" && normalizedMethod === "POST") {
|
|
90
|
+
return true
|
|
91
|
+
}
|
|
92
|
+
|
|
75
93
|
if (
|
|
76
94
|
pathname.startsWith("/auth/assets/") &&
|
|
77
95
|
(normalizedMethod === "GET" || normalizedMethod === "HEAD")
|
package/src/auth/scope.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { OntologySource } from "@sixb/core"
|
|
2
2
|
import type { RequestExecutionAuthorization, Sixb } from "@sixb/core/internal/request-execution"
|
|
3
|
-
import type { AgentRunRecord } from "@sixb/core/storage"
|
|
3
|
+
import type { AgentRunRecord, ConversationAgentRunRecord } from "@sixb/core/storage"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Per-request authorization state attached by the server's auth derive.
|
|
@@ -11,10 +11,11 @@ import type { AgentRunRecord } from "@sixb/core/storage"
|
|
|
11
11
|
export interface RequestAuthState {
|
|
12
12
|
readonly sixb: Sixb<readonly OntologySource[]> | null
|
|
13
13
|
/** Present for requests proxied through the run-scoped agent API gateway. */
|
|
14
|
-
readonly agentRun?:
|
|
14
|
+
readonly agentRun?: ConversationAgentRunRecord
|
|
15
15
|
/** Identifies which kind of active agent execution owns a gateway request. */
|
|
16
16
|
readonly agentExecution?:
|
|
17
17
|
| { readonly kind: "conversation"; readonly runId: string }
|
|
18
|
+
| { readonly kind: "subagent"; readonly runId: string; readonly parentRunId: string }
|
|
18
19
|
| { readonly kind: "workflow"; readonly nodeRunId: string }
|
|
19
20
|
}
|
|
20
21
|
|
package/src/files/content.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from "node:crypto"
|
|
1
2
|
import { type BlobInfo, type BlobStorage, type FileRef, isFileRef } from "@sixb/core"
|
|
2
3
|
import { BlobStorageError, supportsRangeRead } from "@sixb/core/blob-storage/server"
|
|
3
4
|
import { ZodError } from "zod"
|
|
@@ -10,6 +11,8 @@ export interface FileContentResponseInput {
|
|
|
10
11
|
readonly disposition?: FileContentDisposition
|
|
11
12
|
readonly head?: boolean
|
|
12
13
|
readonly rangeHeader?: string | null
|
|
14
|
+
readonly ifNoneMatchHeader?: string | null
|
|
15
|
+
readonly ifRangeHeader?: string | null
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
export interface FileContentQuery {
|
|
@@ -82,6 +85,9 @@ export function fileContentGetResponses(options: FileContentResponsesOptions = {
|
|
|
82
85
|
},
|
|
83
86
|
},
|
|
84
87
|
},
|
|
88
|
+
304: {
|
|
89
|
+
description: "File representation is unchanged; reuse the privately cached content",
|
|
90
|
+
},
|
|
85
91
|
400: {
|
|
86
92
|
description: "Response for status 400",
|
|
87
93
|
content: {
|
|
@@ -113,6 +119,9 @@ export function fileContentHeadResponses(options: FileContentResponsesOptions =
|
|
|
113
119
|
206: {
|
|
114
120
|
description: "Partial file content headers",
|
|
115
121
|
},
|
|
122
|
+
304: {
|
|
123
|
+
description: "File representation is unchanged; reuse the privately cached content",
|
|
124
|
+
},
|
|
116
125
|
400: {
|
|
117
126
|
description: "Response for status 400",
|
|
118
127
|
content: {
|
|
@@ -146,7 +155,18 @@ export async function createFileContentResponse(
|
|
|
146
155
|
|
|
147
156
|
const canReadRange = supportsRangeRead(input.blobStorage)
|
|
148
157
|
const headers = fileContentHeaders(input.fileRef, stat, input.disposition, canReadRange)
|
|
149
|
-
|
|
158
|
+
const etag = headers.get("etag")!
|
|
159
|
+
if (matchesIfNoneMatch(input.ifNoneMatchHeader, etag)) {
|
|
160
|
+
headers.delete("content-length")
|
|
161
|
+
return new Response(null, { status: 304, headers })
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Date validators are unsupported: only a strong ETag can validate a range.
|
|
165
|
+
if (
|
|
166
|
+
canReadRange &&
|
|
167
|
+
input.rangeHeader &&
|
|
168
|
+
(input.ifRangeHeader == null || input.ifRangeHeader.trim() === etag)
|
|
169
|
+
) {
|
|
150
170
|
const range = parseSingleByteRange(input.rangeHeader, stat.sizeBytes)
|
|
151
171
|
if (!range) {
|
|
152
172
|
return rangeNotSatisfiableResponse(stat.sizeBytes)
|
|
@@ -213,6 +233,8 @@ export async function createContextualFileContentResponse<TQuery extends FileCon
|
|
|
213
233
|
disposition: parsed.disposition,
|
|
214
234
|
head: input.head,
|
|
215
235
|
rangeHeader: input.request.headers.get("range"),
|
|
236
|
+
ifNoneMatchHeader: input.request.headers.get("if-none-match"),
|
|
237
|
+
ifRangeHeader: input.request.headers.get("if-range"),
|
|
216
238
|
})
|
|
217
239
|
if (!response) {
|
|
218
240
|
return fileContentNotFound(input.set, missingMessage)
|
|
@@ -254,6 +276,13 @@ function blobMatchesFileRef(stat: BlobInfo, fileRef: FileRef): boolean {
|
|
|
254
276
|
)
|
|
255
277
|
}
|
|
256
278
|
|
|
279
|
+
function matchesIfNoneMatch(header: string | null | undefined, etag: string): boolean {
|
|
280
|
+
return (
|
|
281
|
+
header?.trim() === "*" ||
|
|
282
|
+
(header?.split(",").some((value) => value.trim().replace(/^W\//, "") === etag) ?? false)
|
|
283
|
+
)
|
|
284
|
+
}
|
|
285
|
+
|
|
257
286
|
function resolveJsonPointer(root: unknown, pointer: string): unknown {
|
|
258
287
|
if (pointer === "") {
|
|
259
288
|
return root
|
|
@@ -307,12 +336,16 @@ function fileContentHeaders(
|
|
|
307
336
|
headers.set("content-type", mediaType)
|
|
308
337
|
headers.set("content-length", stat.sizeBytes.toString())
|
|
309
338
|
headers.set("content-disposition", contentDispositionHeader(disposition, fileNameFor(fileRef)))
|
|
310
|
-
|
|
339
|
+
// Metadata belongs to the reference, not the blob; changing it must also invalidate caches.
|
|
340
|
+
const representation = JSON.stringify([
|
|
341
|
+
fileRef.digest,
|
|
342
|
+
mediaType,
|
|
343
|
+
headers.get("content-disposition"),
|
|
344
|
+
])
|
|
345
|
+
headers.set("etag", `"sha256:${createHash("sha256").update(representation).digest("hex")}"`)
|
|
311
346
|
headers.set("x-content-type-options", "nosniff")
|
|
312
|
-
//
|
|
313
|
-
|
|
314
|
-
// land in a shared cache.
|
|
315
|
-
headers.set("cache-control", "private, max-age=31536000, immutable")
|
|
347
|
+
// The containing record is mutable even though its referenced blob is immutable.
|
|
348
|
+
headers.set("cache-control", "private, no-cache")
|
|
316
349
|
if (canReadRange) {
|
|
317
350
|
headers.set("accept-ranges", "bytes")
|
|
318
351
|
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { LanguageModelEntry } from "@sixb/core"
|
|
2
|
+
import {
|
|
3
|
+
defineLanguageModel,
|
|
4
|
+
type LanguageModelDefinition,
|
|
5
|
+
ModelCatalogUnavailableError,
|
|
6
|
+
type ModelReasoningLevel,
|
|
7
|
+
} from "@sixb/core/models"
|
|
8
|
+
|
|
9
|
+
/** Presentation only; the configured provider remains the source of model capabilities. */
|
|
10
|
+
export async function languageModelDisplay(entry: LanguageModelEntry) {
|
|
11
|
+
let definition = entry.model.definition
|
|
12
|
+
try {
|
|
13
|
+
const resolved = await entry.model.resolve?.()
|
|
14
|
+
if (resolved) {
|
|
15
|
+
if (resolved.providerId !== entry.provider || resolved.modelId !== entry.modelId) {
|
|
16
|
+
throw new Error("[SixbServer] Resolved model identity does not match its catalog entry.")
|
|
17
|
+
}
|
|
18
|
+
definition = resolved.definition
|
|
19
|
+
}
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (!(error instanceof ModelCatalogUnavailableError)) throw error
|
|
22
|
+
console.warn(
|
|
23
|
+
`[SixbServer] Model metadata is unavailable for '${entry.provider}/${entry.modelId}'; using its configured definition.`
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
definition = defineLanguageModel(definition)
|
|
27
|
+
if (definition.providerId !== entry.provider || definition.modelId !== entry.modelId) {
|
|
28
|
+
throw new Error("[SixbServer] Model definition identity does not match its catalog entry.")
|
|
29
|
+
}
|
|
30
|
+
const gateway = entry.provider === "vercel-ai-gateway"
|
|
31
|
+
const publisherId = gateway ? entry.modelId.split("/")[0]! : entry.provider
|
|
32
|
+
const capabilities = definition.capabilities
|
|
33
|
+
const media = capabilities.inputMediaTypes
|
|
34
|
+
const input = ["text"]
|
|
35
|
+
for (const [kind, mime] of [
|
|
36
|
+
["image", "image/"],
|
|
37
|
+
["audio", "audio/"],
|
|
38
|
+
["video", "video/"],
|
|
39
|
+
["pdf", "application/pdf"],
|
|
40
|
+
]) {
|
|
41
|
+
if (media === "any" || media?.some((type) => type.startsWith(mime!))) input.push(kind!)
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
name: definition.name ?? entry.modelId,
|
|
45
|
+
...(definition.description === undefined ? {} : { description: definition.description }),
|
|
46
|
+
publisher: { id: publisherId, name: publisherName(publisherId) },
|
|
47
|
+
...(gateway ? { via: "AI Gateway" } : {}),
|
|
48
|
+
capabilities: {
|
|
49
|
+
input,
|
|
50
|
+
output: ["text"],
|
|
51
|
+
...(media === undefined ? {} : { attachments: media === "any" || media.length > 0 }),
|
|
52
|
+
...(capabilities.reasoning === undefined
|
|
53
|
+
? {}
|
|
54
|
+
: { reasoning: capabilities.reasoning !== false }),
|
|
55
|
+
...(capabilities.localTools === undefined ? {} : { tools: capabilities.localTools }),
|
|
56
|
+
...(capabilities.nativeStructuredOutput === undefined
|
|
57
|
+
? {}
|
|
58
|
+
: { structuredOutput: capabilities.nativeStructuredOutput }),
|
|
59
|
+
...(definition.contextWindow === undefined
|
|
60
|
+
? {}
|
|
61
|
+
: { contextWindowTokens: definition.contextWindow }),
|
|
62
|
+
},
|
|
63
|
+
reasoningLevels: reasoningLevels(definition),
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function reasoningLevels(definition: LanguageModelDefinition): readonly ModelReasoningLevel[] {
|
|
68
|
+
const reasoning = definition.capabilities.reasoning
|
|
69
|
+
if (!reasoning) return []
|
|
70
|
+
return [
|
|
71
|
+
"provider-default",
|
|
72
|
+
...(reasoning.canDisable ? ["none" as const] : []),
|
|
73
|
+
...(reasoning.efforts ?? []),
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function publisherName(id: string): string {
|
|
78
|
+
const names: Readonly<Record<string, string>> = {
|
|
79
|
+
openai: "OpenAI",
|
|
80
|
+
anthropic: "Anthropic",
|
|
81
|
+
deepseek: "DeepSeek",
|
|
82
|
+
google: "Google",
|
|
83
|
+
xai: "xAI",
|
|
84
|
+
spacexai: "xAI",
|
|
85
|
+
zai: "Z.ai",
|
|
86
|
+
meta: "Meta",
|
|
87
|
+
moonshotai: "Moonshot AI",
|
|
88
|
+
nvidia: "NVIDIA",
|
|
89
|
+
}
|
|
90
|
+
return Object.hasOwn(names, id) ? names[id]! : id
|
|
91
|
+
}
|
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SixbHostView } from "@sixb/core"
|
|
2
2
|
import { assertAgentExecutionRecord } from "@sixb/core/internal/agent-execution"
|
|
3
3
|
import {
|
|
4
4
|
AGENT_API_GATEWAY_PREFIX,
|
|
5
5
|
AGENT_API_ROUTES,
|
|
6
|
+
type AgentExecutionAuthorization,
|
|
6
7
|
isAllowedAgentApiRequest,
|
|
7
8
|
isValidAgentApiGatewayCapability,
|
|
8
9
|
resolveAgentExecutionAuthorization,
|
|
10
|
+
resolveInheritedAgentExecutionAuthorization,
|
|
9
11
|
} from "@sixb/core/internal/agents"
|
|
10
12
|
import { normalizeRoutePath, pathSegmentsFor } from "@sixb/core/internal/http"
|
|
13
|
+
import type { RequestExecutionAuthorization } from "@sixb/core/internal/request-execution"
|
|
14
|
+
import type {
|
|
15
|
+
AgentRunRecord,
|
|
16
|
+
AuthStorage,
|
|
17
|
+
ConversationAgentRunRecord,
|
|
18
|
+
ExecutionRecord,
|
|
19
|
+
WorkflowAgentNodeRunRecord,
|
|
20
|
+
} from "@sixb/core/storage"
|
|
11
21
|
import type { Elysia } from "elysia"
|
|
12
|
-
import { registerInternalRequestAuthState } from "../auth/scope"
|
|
22
|
+
import { type InternalRequestAuthState, registerInternalRequestAuthState } from "../auth/scope"
|
|
13
23
|
import { DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES } from "./files"
|
|
14
24
|
|
|
15
25
|
const MAX_AGENT_API_BODY_BYTES = 1_000_000
|
|
@@ -78,11 +88,16 @@ async function handleAgentApiGatewayRequest(input: {
|
|
|
78
88
|
return authState
|
|
79
89
|
}
|
|
80
90
|
if (
|
|
81
|
-
authState.agentExecution.kind
|
|
91
|
+
authState.agentExecution.kind !== "conversation" &&
|
|
82
92
|
input.request.method === "POST" &&
|
|
83
93
|
matchesWorkflowRunStart(upstreamPath)
|
|
84
94
|
) {
|
|
85
|
-
return jsonError(
|
|
95
|
+
return jsonError(
|
|
96
|
+
409,
|
|
97
|
+
authState.agentExecution.kind === "workflow"
|
|
98
|
+
? "Workflow agent nodes cannot start another workflow run."
|
|
99
|
+
: "Child agents cannot start a workflow run."
|
|
100
|
+
)
|
|
86
101
|
}
|
|
87
102
|
|
|
88
103
|
let body: ArrayBuffer | undefined
|
|
@@ -128,32 +143,26 @@ async function resolveAgentRunAuthState(
|
|
|
128
143
|
return jsonError(501, "Agent API gateway is not configured for this runtime.")
|
|
129
144
|
}
|
|
130
145
|
|
|
131
|
-
const
|
|
146
|
+
const storedAgentRun = await agentStorage?.runs.getById({
|
|
132
147
|
projectId: host.id,
|
|
133
148
|
id: input.runId,
|
|
134
149
|
})
|
|
135
|
-
const workflowRun =
|
|
150
|
+
const workflowRun = storedAgentRun
|
|
136
151
|
? null
|
|
137
152
|
: await workflowRuns?.agentNodes.getByNodeRunId({
|
|
138
153
|
projectId: host.id,
|
|
139
154
|
nodeRunId: input.runId,
|
|
140
155
|
})
|
|
141
|
-
const
|
|
142
|
-
const agentExecution = conversationalRun
|
|
143
|
-
? ({ kind: "conversation", runId: conversationalRun.id } as const)
|
|
144
|
-
: workflowRun
|
|
145
|
-
? ({ kind: "workflow", nodeRunId: workflowRun.nodeRunId } as const)
|
|
146
|
-
: null
|
|
156
|
+
const runState = toGatewayRunState(storedAgentRun ?? null, workflowRun ?? null)
|
|
147
157
|
if (
|
|
148
|
-
!
|
|
149
|
-
|
|
150
|
-
run.
|
|
151
|
-
|
|
152
|
-
run.execution.queueLeaseExpiresAt.getTime() <= Date.now() ||
|
|
158
|
+
!runState ||
|
|
159
|
+
runState.run.status !== "running" ||
|
|
160
|
+
!runState.run.execution ||
|
|
161
|
+
runState.run.execution.queueLeaseExpiresAt.getTime() <= Date.now() ||
|
|
153
162
|
!isValidAgentApiGatewayCapability({
|
|
154
163
|
projectId: host.id,
|
|
155
164
|
runId: input.runId,
|
|
156
|
-
executionToken: run.execution.token,
|
|
165
|
+
executionToken: runState.run.execution.token,
|
|
157
166
|
capability: input.capability,
|
|
158
167
|
})
|
|
159
168
|
) {
|
|
@@ -163,8 +172,8 @@ async function resolveAgentRunAuthState(
|
|
|
163
172
|
if (!host.auth.isEnabled()) {
|
|
164
173
|
return {
|
|
165
174
|
authorization: { type: "disabled" as const },
|
|
166
|
-
agentExecution,
|
|
167
|
-
...(
|
|
175
|
+
agentExecution: runState.agentExecution,
|
|
176
|
+
...(runState.agentRun === undefined ? {} : { agentRun: runState.agentRun }),
|
|
168
177
|
}
|
|
169
178
|
}
|
|
170
179
|
|
|
@@ -174,36 +183,126 @@ async function resolveAgentRunAuthState(
|
|
|
174
183
|
}
|
|
175
184
|
const execution = await host.storage.executions.getById({
|
|
176
185
|
projectId: host.id,
|
|
177
|
-
id: run.executionId,
|
|
186
|
+
id: runState.run.executionId,
|
|
178
187
|
})
|
|
179
188
|
if (!execution) {
|
|
180
189
|
return jsonError(403, "Agent run execution is not available.")
|
|
181
190
|
}
|
|
182
191
|
|
|
183
|
-
let
|
|
192
|
+
let authorization: RequestExecutionAuthorization
|
|
184
193
|
try {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
194
|
+
authorization = await resolveGatewayRunAuthorization({ host, auth, runState, execution })
|
|
195
|
+
} catch {
|
|
196
|
+
return jsonError(403, "Agent run execution authority is not valid.")
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
authorization,
|
|
201
|
+
agentExecution: runState.agentExecution,
|
|
202
|
+
...(runState.agentRun === undefined ? {} : { agentRun: runState.agentRun }),
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
type GatewayRunState = {
|
|
207
|
+
readonly run: AgentRunRecord | WorkflowAgentNodeRunRecord
|
|
208
|
+
readonly runId: string
|
|
209
|
+
readonly agentExecution: NonNullable<InternalRequestAuthState["agentExecution"]>
|
|
210
|
+
readonly agentRun?: ConversationAgentRunRecord
|
|
211
|
+
} & (
|
|
212
|
+
| { readonly authority: "inherited" }
|
|
213
|
+
| { readonly authority: "managed"; readonly actorId: string }
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
function toGatewayRunState(
|
|
217
|
+
storedRun: AgentRunRecord | null,
|
|
218
|
+
workflowRun: WorkflowAgentNodeRunRecord | null
|
|
219
|
+
): GatewayRunState | null {
|
|
220
|
+
if (storedRun?.kind === "subagent") {
|
|
221
|
+
return {
|
|
222
|
+
run: storedRun,
|
|
223
|
+
runId: storedRun.id,
|
|
224
|
+
agentExecution: {
|
|
225
|
+
kind: "subagent",
|
|
226
|
+
runId: storedRun.id,
|
|
227
|
+
parentRunId: storedRun.parentRunId,
|
|
228
|
+
},
|
|
229
|
+
authority: "inherited",
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (storedRun?.kind === "conversation") {
|
|
234
|
+
const common = {
|
|
235
|
+
run: storedRun,
|
|
236
|
+
runId: storedRun.id,
|
|
237
|
+
agentExecution: { kind: "conversation", runId: storedRun.id } as const,
|
|
238
|
+
agentRun: storedRun,
|
|
239
|
+
}
|
|
240
|
+
return { ...common, authority: "inherited" }
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (!workflowRun) return null
|
|
244
|
+
const common = {
|
|
245
|
+
run: workflowRun,
|
|
246
|
+
runId: workflowRun.nodeRunId,
|
|
247
|
+
agentExecution: { kind: "workflow", nodeRunId: workflowRun.nodeRunId } as const,
|
|
248
|
+
}
|
|
249
|
+
return { ...common, authority: "managed", actorId: workflowRun.actorId }
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
async function resolveGatewayRunAuthorization(input: {
|
|
253
|
+
readonly host: SixbHostView
|
|
254
|
+
readonly auth: AuthStorage
|
|
255
|
+
readonly runState: GatewayRunState
|
|
256
|
+
readonly execution: ExecutionRecord
|
|
257
|
+
}): Promise<RequestExecutionAuthorization> {
|
|
258
|
+
if (input.runState.authority === "inherited") {
|
|
259
|
+
const resolved = await resolveInheritedAgentExecutionAuthorization({
|
|
260
|
+
auth: input.auth,
|
|
261
|
+
projectId: input.host.id,
|
|
262
|
+
authorizationRef: input.execution.authorizationRef,
|
|
263
|
+
security: input.host.definitions.security,
|
|
191
264
|
})
|
|
265
|
+
const authorization = inheritedRequestAuthorization(resolved, input.execution.authorizationRef)
|
|
192
266
|
assertAgentExecutionRecord({
|
|
193
|
-
execution,
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
authorization: resolved.context,
|
|
267
|
+
execution: input.execution,
|
|
268
|
+
runId: input.runState.runId,
|
|
269
|
+
authorization,
|
|
197
270
|
})
|
|
198
|
-
|
|
199
|
-
} catch {
|
|
200
|
-
return jsonError(403, "Agent run execution authority is not valid.")
|
|
271
|
+
return authorization
|
|
201
272
|
}
|
|
202
273
|
|
|
274
|
+
const resolved = await resolveAgentExecutionAuthorization({
|
|
275
|
+
auth: input.auth,
|
|
276
|
+
projectId: input.host.id,
|
|
277
|
+
actorId: input.runState.actorId,
|
|
278
|
+
authorizationRef: input.execution.authorizationRef,
|
|
279
|
+
security: input.host.definitions.security,
|
|
280
|
+
})
|
|
281
|
+
const authorization = { type: "principal", context: resolved.context } as const
|
|
282
|
+
assertAgentExecutionRecord({
|
|
283
|
+
execution: input.execution,
|
|
284
|
+
actorId: input.runState.actorId,
|
|
285
|
+
runId: input.runState.runId,
|
|
286
|
+
authorization,
|
|
287
|
+
})
|
|
288
|
+
return authorization
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function inheritedRequestAuthorization(
|
|
292
|
+
resolved: AgentExecutionAuthorization,
|
|
293
|
+
authorizationRef: ExecutionRecord["authorizationRef"]
|
|
294
|
+
): RequestExecutionAuthorization {
|
|
295
|
+
if (
|
|
296
|
+
resolved.type !== "principal" ||
|
|
297
|
+
authorizationRef.type !== "principal" ||
|
|
298
|
+
authorizationRef.credential === undefined
|
|
299
|
+
) {
|
|
300
|
+
return resolved
|
|
301
|
+
}
|
|
203
302
|
return {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
303
|
+
type: "principal",
|
|
304
|
+
context: resolved.context,
|
|
305
|
+
credential: authorizationRef.credential,
|
|
207
306
|
}
|
|
208
307
|
}
|
|
209
308
|
|