@sixb/server 0.1.2 → 0.1.4
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 +1 -1
- package/dist/auth/experience.d.ts +33 -0
- package/dist/auth/experience.d.ts.map +1 -0
- package/dist/auth/public-routes.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2122 -1391
- package/dist/index.js.map +24 -19
- package/dist/openapi/tags.d.ts +10 -2
- package/dist/openapi/tags.d.ts.map +1 -1
- package/dist/registerRoutes.d.ts.map +1 -1
- package/dist/routes/action-runs.d.ts +6 -6
- package/dist/routes/actions.d.ts +3 -3
- package/dist/routes/agents.d.ts +164 -77
- 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 +110 -53
- package/dist/routes/auth.d.ts.map +1 -1
- package/dist/routes/connector-connection-runs.d.ts +56 -56
- package/dist/routes/connector-connections.d.ts +14 -14
- package/dist/routes/datasets.d.ts +12 -12
- package/dist/routes/events.d.ts +1 -1
- package/dist/routes/files.d.ts +8 -8
- package/dist/routes/links.d.ts +6 -57
- package/dist/routes/links.d.ts.map +1 -1
- package/dist/routes/logs.d.ts +3 -3
- package/dist/routes/models.d.ts +60 -0
- package/dist/routes/models.d.ts.map +1 -0
- package/dist/routes/objects.d.ts +51 -3
- package/dist/routes/objects.d.ts.map +1 -1
- package/dist/routes/pipelines.d.ts +10 -10
- package/dist/routes/projections.d.ts +150 -136
- package/dist/routes/projections.d.ts.map +1 -1
- package/dist/routes/syncs.d.ts +38 -38
- package/dist/routes/telemetry.d.ts +7 -7
- package/dist/routes/webhook-runs.d.ts +2 -2
- package/dist/routes/workflows.d.ts +142 -57
- package/dist/routes/workflows.d.ts.map +1 -1
- package/dist/routes/ws/logs.d.ts +10 -10
- package/dist/schemas/actions.d.ts +16 -16
- package/dist/schemas/agents.d.ts +586 -142
- 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/auth.d.ts +96 -96
- package/dist/schemas/connectors.d.ts +35 -25
- package/dist/schemas/connectors.d.ts.map +1 -1
- package/dist/schemas/event-payloads.d.ts +6 -6
- package/dist/schemas/events.d.ts +6 -6
- package/dist/schemas/links.d.ts +0 -41
- package/dist/schemas/links.d.ts.map +1 -1
- package/dist/schemas/logs.d.ts +22 -22
- package/dist/schemas/models.d.ts +50 -0
- package/dist/schemas/models.d.ts.map +1 -0
- package/dist/schemas/objects.d.ts +22 -0
- package/dist/schemas/objects.d.ts.map +1 -1
- package/dist/schemas/pipelines.d.ts +20 -20
- package/dist/schemas/projections.d.ts +947 -806
- package/dist/schemas/projections.d.ts.map +1 -1
- package/dist/schemas/status.d.ts +2 -2
- package/dist/schemas/syncs.d.ts +33 -33
- package/dist/schemas/webhook-runs.d.ts +12 -12
- package/dist/schemas/workflows.d.ts +833 -162
- package/dist/schemas/workflows.d.ts.map +1 -1
- package/dist/server.d.ts +5 -0
- package/dist/server.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/auth/experience.ts +190 -0
- package/src/auth/public-routes.ts +7 -0
- package/src/index.ts +1 -0
- package/src/openapi/tags.ts +8 -0
- package/src/registerRoutes.ts +4 -0
- package/src/routes/agents.ts +22 -3
- package/src/routes/ai-accounting.ts +166 -0
- package/src/routes/auth.ts +188 -32
- package/src/routes/links.ts +2 -53
- package/src/routes/models.ts +31 -0
- package/src/routes/objects.ts +103 -0
- package/src/routes/projections.ts +18 -4
- package/src/routes/workflows.ts +16 -0
- package/src/schemas/agents.ts +19 -9
- package/src/schemas/ai-accounting.ts +182 -0
- package/src/schemas/connectors.ts +13 -3
- package/src/schemas/links.ts +0 -17
- package/src/schemas/models.ts +15 -0
- package/src/schemas/objects.ts +104 -0
- package/src/schemas/projections.ts +12 -3
- package/src/schemas/workflows.ts +8 -3
- package/src/server.ts +10 -0
package/src/routes/auth.ts
CHANGED
|
@@ -39,6 +39,11 @@ import {
|
|
|
39
39
|
type ResolveRequestAuthContext,
|
|
40
40
|
} from "../auth/browser-origin"
|
|
41
41
|
import { CSRF_TOKEN_RESPONSE_HEADER_NAME } from "../auth/csrf"
|
|
42
|
+
import {
|
|
43
|
+
customAuthExperienceAssetResponse,
|
|
44
|
+
customAuthExperienceResponse,
|
|
45
|
+
type SixbAuthExperienceOptions,
|
|
46
|
+
} from "../auth/experience"
|
|
42
47
|
import { hasForegroundSessionActivity } from "../auth/session-activity"
|
|
43
48
|
import { createSessionRenewalCookieHeaders } from "../auth/session-cookies"
|
|
44
49
|
import { SIXB_CSRF_SECURITY_REQUIREMENT } from "../openapi/security"
|
|
@@ -115,10 +120,21 @@ export interface AuthRoutesOptions {
|
|
|
115
120
|
request: Request,
|
|
116
121
|
input: AuthInvitationRedirectInput
|
|
117
122
|
) => AuthInvitationRedirectContext
|
|
123
|
+
readonly authExperience?: SixbAuthExperienceOptions
|
|
118
124
|
}
|
|
119
125
|
|
|
120
126
|
export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: AuthRoutesOptions) {
|
|
121
127
|
return app
|
|
128
|
+
.get(
|
|
129
|
+
"/auth/assets/*",
|
|
130
|
+
async ({ request }) => customAuthExperienceAssetResponse(options.authExperience, request),
|
|
131
|
+
{ detail: { hide: true } }
|
|
132
|
+
)
|
|
133
|
+
.head(
|
|
134
|
+
"/auth/assets/*",
|
|
135
|
+
async ({ request }) => customAuthExperienceAssetResponse(options.authExperience, request),
|
|
136
|
+
{ detail: { hide: true } }
|
|
137
|
+
)
|
|
122
138
|
.get(
|
|
123
139
|
"/api/auth/session",
|
|
124
140
|
async ({ request }) => {
|
|
@@ -1241,11 +1257,7 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
|
|
|
1241
1257
|
requesterHash: pending.hash,
|
|
1242
1258
|
})
|
|
1243
1259
|
|
|
1244
|
-
const response =
|
|
1245
|
-
"If this email can sign in, we sent a link. Check your inbox to continue.",
|
|
1246
|
-
200,
|
|
1247
|
-
"Check your email"
|
|
1248
|
-
)
|
|
1260
|
+
const response = await magicLinkRequestedResponse(options, authRedirect)
|
|
1249
1261
|
// Same-device fast path: this browser keeps the preimage of the
|
|
1250
1262
|
// `requester` hash embedded in the emailed callback URL, so opening
|
|
1251
1263
|
// the link here signs in without the confirmation click. Always
|
|
@@ -1304,7 +1316,7 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
|
|
|
1304
1316
|
}
|
|
1305
1317
|
|
|
1306
1318
|
if (isMagicLinkAuthStrategy(strategy)) {
|
|
1307
|
-
return signInFormResponse(authRedirect)
|
|
1319
|
+
return await signInFormResponse(options, authRedirect)
|
|
1308
1320
|
}
|
|
1309
1321
|
|
|
1310
1322
|
if (isOidcAuthStrategy(strategy)) {
|
|
@@ -1331,9 +1343,14 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
|
|
|
1331
1343
|
const url = new URL(request.url)
|
|
1332
1344
|
const magicLinkId = url.searchParams.get("magicLinkId")?.trim()
|
|
1333
1345
|
const token = url.searchParams.get("token")?.trim()
|
|
1346
|
+
const authRedirectHint = resolveAuthExperienceRedirectHint(
|
|
1347
|
+
options,
|
|
1348
|
+
request,
|
|
1349
|
+
url.searchParams.get("audience")
|
|
1350
|
+
)
|
|
1334
1351
|
|
|
1335
1352
|
if (!magicLinkId || !token) {
|
|
1336
|
-
return
|
|
1353
|
+
return await invalidMagicLinkResponse(options, authRedirectHint)
|
|
1337
1354
|
}
|
|
1338
1355
|
|
|
1339
1356
|
// Read-only peek so the page can greet the user by email and dead
|
|
@@ -1353,11 +1370,12 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
|
|
|
1353
1370
|
token,
|
|
1354
1371
|
})
|
|
1355
1372
|
if (!peeked) {
|
|
1356
|
-
return
|
|
1373
|
+
return await invalidMagicLinkResponse(options, authRedirectHint)
|
|
1357
1374
|
}
|
|
1358
1375
|
email = peeked.email
|
|
1359
|
-
} catch {
|
|
1360
|
-
|
|
1376
|
+
} catch (error) {
|
|
1377
|
+
logAuthCallbackError("Magic-link", error)
|
|
1378
|
+
return await authExperienceErrorResponse(options, authRedirectHint)
|
|
1361
1379
|
}
|
|
1362
1380
|
}
|
|
1363
1381
|
|
|
@@ -1380,10 +1398,16 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
|
|
|
1380
1398
|
magicLinkId,
|
|
1381
1399
|
token,
|
|
1382
1400
|
clearPendingCookie: true,
|
|
1401
|
+
authRedirectHint,
|
|
1383
1402
|
})
|
|
1384
1403
|
}
|
|
1385
1404
|
|
|
1386
|
-
return magicLinkConfirmResponse(
|
|
1405
|
+
return await magicLinkConfirmResponse(options, {
|
|
1406
|
+
magicLinkId,
|
|
1407
|
+
token,
|
|
1408
|
+
email,
|
|
1409
|
+
authRedirect: authRedirectHint,
|
|
1410
|
+
})
|
|
1387
1411
|
}
|
|
1388
1412
|
|
|
1389
1413
|
if (isOidcAuthStrategy(strategy)) {
|
|
@@ -1438,16 +1462,26 @@ export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: Aut
|
|
|
1438
1462
|
|
|
1439
1463
|
const magicLinkId = body.magicLinkId?.trim()
|
|
1440
1464
|
const token = body.token?.trim()
|
|
1465
|
+
const authRedirectHint = resolveAuthExperienceRedirectHint(options, request, body.audience)
|
|
1441
1466
|
if (!magicLinkId || !token) {
|
|
1442
|
-
return
|
|
1467
|
+
return await invalidMagicLinkResponse(options, authRedirectHint)
|
|
1443
1468
|
}
|
|
1444
1469
|
|
|
1445
|
-
return completeMagicLinkCallback({
|
|
1470
|
+
return completeMagicLinkCallback({
|
|
1471
|
+
host,
|
|
1472
|
+
strategy,
|
|
1473
|
+
options,
|
|
1474
|
+
request,
|
|
1475
|
+
magicLinkId,
|
|
1476
|
+
token,
|
|
1477
|
+
authRedirectHint,
|
|
1478
|
+
})
|
|
1446
1479
|
},
|
|
1447
1480
|
{
|
|
1448
1481
|
body: t.Object({
|
|
1449
1482
|
magicLinkId: t.Optional(t.String()),
|
|
1450
1483
|
token: t.Optional(t.String()),
|
|
1484
|
+
audience: t.Optional(t.String()),
|
|
1451
1485
|
}),
|
|
1452
1486
|
parse: "urlencoded",
|
|
1453
1487
|
detail: { hide: true },
|
|
@@ -1520,6 +1554,7 @@ async function completeMagicLinkCallback(input: {
|
|
|
1520
1554
|
readonly magicLinkId: string
|
|
1521
1555
|
readonly token: string
|
|
1522
1556
|
readonly clearPendingCookie?: boolean
|
|
1557
|
+
readonly authRedirectHint?: AuthRedirectContext
|
|
1523
1558
|
}): Promise<Response> {
|
|
1524
1559
|
const authOptions = resolveAuthOptions(input.options, input.request)
|
|
1525
1560
|
const now = new Date()
|
|
@@ -1564,7 +1599,7 @@ async function completeMagicLinkCallback(input: {
|
|
|
1564
1599
|
}
|
|
1565
1600
|
return response
|
|
1566
1601
|
} catch {
|
|
1567
|
-
return
|
|
1602
|
+
return await invalidMagicLinkResponse(input.options, input.authRedirectHint)
|
|
1568
1603
|
}
|
|
1569
1604
|
}
|
|
1570
1605
|
|
|
@@ -1925,21 +1960,110 @@ function authPageResponse(body: string, status = 200): Response {
|
|
|
1925
1960
|
})
|
|
1926
1961
|
}
|
|
1927
1962
|
|
|
1928
|
-
function signInFormResponse(
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1963
|
+
async function signInFormResponse(
|
|
1964
|
+
options: AuthRoutesOptions,
|
|
1965
|
+
context: AuthRedirectContext
|
|
1966
|
+
): Promise<Response> {
|
|
1967
|
+
return (
|
|
1968
|
+
(await customAuthExperienceResponse(options.authExperience, {
|
|
1969
|
+
audience: context.audience,
|
|
1970
|
+
state: { kind: "signIn" },
|
|
1971
|
+
signInUrl: authExperienceSignInUrl(context),
|
|
1972
|
+
submission: {
|
|
1973
|
+
kind: "requestMagicLink",
|
|
1974
|
+
action: "/auth/sign-in",
|
|
1975
|
+
fields: { audience: context.audience, returnTo: context.returnTo },
|
|
1976
|
+
},
|
|
1977
|
+
// Native POST forms inherit the document's referrer policy when
|
|
1978
|
+
// constructing their Origin header. `no-referrer` produces
|
|
1979
|
+
// `Origin: null`, which the API origin guard correctly rejects.
|
|
1980
|
+
referrerPolicy: "same-origin",
|
|
1981
|
+
})) ??
|
|
1982
|
+
authPageResponse(
|
|
1983
|
+
[
|
|
1984
|
+
"<h1>Sign in</h1>",
|
|
1985
|
+
"<p>We'll email you a sign-in link.</p>",
|
|
1986
|
+
'<form method="post" action="/auth/sign-in">',
|
|
1987
|
+
`<input type="hidden" name="audience" value="${escapeHtml(context.audience)}">`,
|
|
1988
|
+
`<input type="hidden" name="returnTo" value="${escapeHtml(context.returnTo)}">`,
|
|
1989
|
+
'<input name="email" type="email" autocomplete="email" placeholder="you@example.com" aria-label="Email address" required autofocus>',
|
|
1990
|
+
'<button type="submit">Send sign-in link</button>',
|
|
1991
|
+
"</form>",
|
|
1992
|
+
].join("")
|
|
1993
|
+
)
|
|
1940
1994
|
)
|
|
1941
1995
|
}
|
|
1942
1996
|
|
|
1997
|
+
async function magicLinkRequestedResponse(
|
|
1998
|
+
options: AuthRoutesOptions,
|
|
1999
|
+
context: AuthRedirectContext
|
|
2000
|
+
): Promise<Response> {
|
|
2001
|
+
return (
|
|
2002
|
+
(await customAuthExperienceResponse(options.authExperience, {
|
|
2003
|
+
audience: context.audience,
|
|
2004
|
+
state: { kind: "checkEmail" },
|
|
2005
|
+
signInUrl: authExperienceSignInUrl(context),
|
|
2006
|
+
})) ??
|
|
2007
|
+
htmlMessageResponse(
|
|
2008
|
+
"If this email can sign in, we sent a link. Check your inbox to continue.",
|
|
2009
|
+
200,
|
|
2010
|
+
"Check your email"
|
|
2011
|
+
)
|
|
2012
|
+
)
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
async function invalidMagicLinkResponse(
|
|
2016
|
+
options: AuthRoutesOptions,
|
|
2017
|
+
context: AuthRedirectContext | undefined
|
|
2018
|
+
): Promise<Response> {
|
|
2019
|
+
if (context) {
|
|
2020
|
+
const custom = await customAuthExperienceResponse(options.authExperience, {
|
|
2021
|
+
audience: context.audience,
|
|
2022
|
+
state: { kind: "invalidLink" },
|
|
2023
|
+
signInUrl: authExperienceSignInUrl(context),
|
|
2024
|
+
status: 400,
|
|
2025
|
+
})
|
|
2026
|
+
if (custom) return custom
|
|
2027
|
+
}
|
|
2028
|
+
|
|
2029
|
+
return htmlMessageResponse("This sign-in link is invalid or expired.", 400)
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
async function authExperienceErrorResponse(
|
|
2033
|
+
options: AuthRoutesOptions,
|
|
2034
|
+
context: AuthRedirectContext | undefined
|
|
2035
|
+
): Promise<Response> {
|
|
2036
|
+
if (context) {
|
|
2037
|
+
const custom = await customAuthExperienceResponse(options.authExperience, {
|
|
2038
|
+
audience: context.audience,
|
|
2039
|
+
state: { kind: "error" },
|
|
2040
|
+
signInUrl: authExperienceSignInUrl(context),
|
|
2041
|
+
status: 500,
|
|
2042
|
+
})
|
|
2043
|
+
if (custom) return custom
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
return await invalidMagicLinkResponse(options, undefined)
|
|
2047
|
+
}
|
|
2048
|
+
|
|
2049
|
+
function authExperienceSignInUrl(context: AuthRedirectContext): string {
|
|
2050
|
+
const params = new URLSearchParams({ audience: context.audience, returnTo: context.returnTo })
|
|
2051
|
+
return `/auth/sign-in?${params.toString()}`
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
function resolveAuthExperienceRedirectHint(
|
|
2055
|
+
options: AuthRoutesOptions,
|
|
2056
|
+
request: Request,
|
|
2057
|
+
audience: string | null | undefined
|
|
2058
|
+
): AuthRedirectContext | undefined {
|
|
2059
|
+
if (audience !== "app" && audience !== "atlas") {
|
|
2060
|
+
return undefined
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
const context = resolveInvitationDeliveryContext(options, request, { destinationId: audience })
|
|
2064
|
+
return context instanceof Response ? undefined : context
|
|
2065
|
+
}
|
|
2066
|
+
|
|
1943
2067
|
// Deliberately a plain form with no auto-submit: link scanners that execute
|
|
1944
2068
|
// pages headlessly still won't press the button, so the token survives until a
|
|
1945
2069
|
// person clicks Continue. The extra click also keeps the link reusable when a
|
|
@@ -1948,12 +2072,39 @@ function signInFormResponse(context: AuthRedirectContext): Response {
|
|
|
1948
2072
|
// a disabled spinner. The form POST is a normal navigation, so this page stays
|
|
1949
2073
|
// visible (spinner and all) until the server responds; the pageshow handler
|
|
1950
2074
|
// resets the button when the page is restored from the back/forward cache.
|
|
1951
|
-
function magicLinkConfirmResponse(
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
2075
|
+
async function magicLinkConfirmResponse(
|
|
2076
|
+
options: AuthRoutesOptions,
|
|
2077
|
+
input: {
|
|
2078
|
+
readonly magicLinkId: string
|
|
2079
|
+
readonly token: string
|
|
2080
|
+
// Absent when the strategy doesn't support the read-only peek.
|
|
2081
|
+
readonly email?: string
|
|
2082
|
+
readonly authRedirect?: AuthRedirectContext
|
|
2083
|
+
}
|
|
2084
|
+
): Promise<Response> {
|
|
2085
|
+
if (input.authRedirect) {
|
|
2086
|
+
const custom = await customAuthExperienceResponse(options.authExperience, {
|
|
2087
|
+
audience: input.authRedirect.audience,
|
|
2088
|
+
state: { kind: "confirm", ...(input.email ? { email: input.email } : {}) },
|
|
2089
|
+
signInUrl: authExperienceSignInUrl(input.authRedirect),
|
|
2090
|
+
submission: {
|
|
2091
|
+
kind: "confirmSignIn",
|
|
2092
|
+
action: "/auth/callback",
|
|
2093
|
+
fields: {
|
|
2094
|
+
magicLinkId: input.magicLinkId,
|
|
2095
|
+
token: input.token,
|
|
2096
|
+
audience: input.authRedirect.audience,
|
|
2097
|
+
},
|
|
2098
|
+
},
|
|
2099
|
+
referrerPolicy: "same-origin",
|
|
2100
|
+
// The callback POST is same-origin, but its successful 303 continues to
|
|
2101
|
+
// the validated custom-app origin. CSP applies form-action across that
|
|
2102
|
+
// redirect chain, so permit that exact origin for this state only.
|
|
2103
|
+
formActionOrigins: [new URL(input.authRedirect.returnTo).origin],
|
|
2104
|
+
})
|
|
2105
|
+
if (custom) return custom
|
|
2106
|
+
}
|
|
2107
|
+
|
|
1957
2108
|
const response = authPageResponse(
|
|
1958
2109
|
[
|
|
1959
2110
|
"<h1>Sign in</h1>",
|
|
@@ -1963,6 +2114,11 @@ function magicLinkConfirmResponse(input: {
|
|
|
1963
2114
|
'<form method="post" action="/auth/callback" id="confirm">',
|
|
1964
2115
|
`<input type="hidden" name="magicLinkId" value="${escapeHtml(input.magicLinkId)}">`,
|
|
1965
2116
|
`<input type="hidden" name="token" value="${escapeHtml(input.token)}">`,
|
|
2117
|
+
...(input.authRedirect
|
|
2118
|
+
? [
|
|
2119
|
+
`<input type="hidden" name="audience" value="${escapeHtml(input.authRedirect.audience)}">`,
|
|
2120
|
+
]
|
|
2121
|
+
: []),
|
|
1966
2122
|
'<button type="submit" id="confirm-button">Continue</button>',
|
|
1967
2123
|
"</form>",
|
|
1968
2124
|
"<script>",
|
package/src/routes/links.ts
CHANGED
|
@@ -4,62 +4,11 @@ import { bearerSecurityRequirement } from "../auth/access-token-boundary"
|
|
|
4
4
|
import { requireRequestSixb } from "../auth/scope"
|
|
5
5
|
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
6
6
|
import { ErrorResponseSchema, SuccessResponseSchema } from "../schemas/common"
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
LinkQuerySchema,
|
|
10
|
-
LinkSourceParamsSchema,
|
|
11
|
-
ObjectLinkSchema,
|
|
12
|
-
RemoveLinkQuerySchema,
|
|
13
|
-
UpsertLinkBodySchema,
|
|
14
|
-
} from "../schemas/links"
|
|
15
|
-
import { handleRouteError, toIsoString } from "../utils/http"
|
|
7
|
+
import { LinkParamsSchema, RemoveLinkQuerySchema, UpsertLinkBodySchema } from "../schemas/links"
|
|
8
|
+
import { handleRouteError } from "../utils/http"
|
|
16
9
|
|
|
17
10
|
export function registerLinkRoutes(app: Elysia, _host: SixbHostView) {
|
|
18
11
|
return app
|
|
19
|
-
.get(
|
|
20
|
-
"/api/objects/:objectTypeId/:objectId/links",
|
|
21
|
-
async (context) => {
|
|
22
|
-
const { params, query, set } = context
|
|
23
|
-
try {
|
|
24
|
-
const sixb = requireRequestSixb(context)
|
|
25
|
-
if (!sixb.objects.getTypeById(params.objectTypeId)) {
|
|
26
|
-
set.status = 404
|
|
27
|
-
return { error: "Object not found" }
|
|
28
|
-
}
|
|
29
|
-
const parsedQuery = LinkQuerySchema.parse(query)
|
|
30
|
-
const links = await sixb.objects.listLinks({
|
|
31
|
-
objectTypeId: params.objectTypeId,
|
|
32
|
-
objectId: params.objectId,
|
|
33
|
-
linkId: parsedQuery.linkId,
|
|
34
|
-
direction: parsedQuery.direction,
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
return links.map((link) => ({
|
|
38
|
-
...link,
|
|
39
|
-
createdAt: toIsoString(link.createdAt),
|
|
40
|
-
updatedAt: toIsoString(link.updatedAt),
|
|
41
|
-
}))
|
|
42
|
-
} catch (error) {
|
|
43
|
-
set.status = 400
|
|
44
|
-
return { error: error instanceof Error ? error.message : String(error) }
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
params: LinkSourceParamsSchema,
|
|
49
|
-
query: LinkQuerySchema,
|
|
50
|
-
response: {
|
|
51
|
-
200: ObjectLinkSchema.array(),
|
|
52
|
-
400: ErrorResponseSchema,
|
|
53
|
-
404: ErrorResponseSchema,
|
|
54
|
-
},
|
|
55
|
-
detail: {
|
|
56
|
-
summary: "List object links",
|
|
57
|
-
tags: [OPENAPI_TAGS.links.name],
|
|
58
|
-
operationId: "listObjectLinks",
|
|
59
|
-
security: bearerSecurityRequirement("listObjectLinks"),
|
|
60
|
-
},
|
|
61
|
-
}
|
|
62
|
-
)
|
|
63
12
|
.put(
|
|
64
13
|
"/api/objects/:objectTypeId/:objectId/links/:linkId",
|
|
65
14
|
async (context) => {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { LanguageModelEntry, SixbHostView } from "@sixb/core"
|
|
2
|
+
import type { Elysia } from "elysia"
|
|
3
|
+
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
4
|
+
import { ModelCatalogSchema } from "../schemas/models"
|
|
5
|
+
|
|
6
|
+
function serializeLanguageModel(entry: LanguageModelEntry, defaultRef: string) {
|
|
7
|
+
return { provider: entry.provider, modelId: entry.modelId, isDefault: entry.ref === defaultRef }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function registerModelRoutes(app: Elysia, host: SixbHostView) {
|
|
11
|
+
return app.get(
|
|
12
|
+
"/api/models",
|
|
13
|
+
() => {
|
|
14
|
+
const language = host.definitions.models?.language
|
|
15
|
+
return ModelCatalogSchema.parse({
|
|
16
|
+
language:
|
|
17
|
+
language === undefined
|
|
18
|
+
? []
|
|
19
|
+
: language.list().map((entry) => serializeLanguageModel(entry, language.default.ref)),
|
|
20
|
+
})
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
response: { 200: ModelCatalogSchema },
|
|
24
|
+
detail: {
|
|
25
|
+
summary: "List the project model catalog",
|
|
26
|
+
tags: [OPENAPI_TAGS.models.name],
|
|
27
|
+
operationId: "listModels",
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
)
|
|
31
|
+
}
|
package/src/routes/objects.ts
CHANGED
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
ObjectQueryCountRequestSchema,
|
|
32
32
|
ObjectQueryExistsRequestSchema,
|
|
33
33
|
ObjectQueryFacetsRequestSchema,
|
|
34
|
+
ObjectQueryLinksRequestSchema,
|
|
34
35
|
ObjectQueryRequestSchema,
|
|
35
36
|
ObjectSearchQuerySchema,
|
|
36
37
|
ObjectSearchResponseSchema,
|
|
@@ -63,6 +64,32 @@ function serializeObject(row: {
|
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
function serializeObjectLink(link: {
|
|
68
|
+
sourceTypeId: string
|
|
69
|
+
sourceId: string
|
|
70
|
+
linkId: string
|
|
71
|
+
targetTypeId: string
|
|
72
|
+
targetId: string
|
|
73
|
+
properties?: Record<string, unknown>
|
|
74
|
+
createdAt: Date
|
|
75
|
+
updatedAt: Date
|
|
76
|
+
}) {
|
|
77
|
+
return {
|
|
78
|
+
source: {
|
|
79
|
+
objectTypeId: link.sourceTypeId,
|
|
80
|
+
primaryId: link.sourceId,
|
|
81
|
+
},
|
|
82
|
+
linkId: link.linkId,
|
|
83
|
+
target: {
|
|
84
|
+
objectTypeId: link.targetTypeId,
|
|
85
|
+
primaryId: link.targetId,
|
|
86
|
+
},
|
|
87
|
+
...(link.properties === undefined ? {} : { properties: link.properties }),
|
|
88
|
+
createdAt: toIsoString(link.createdAt),
|
|
89
|
+
updatedAt: toIsoString(link.updatedAt),
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
66
93
|
type SerializedObject = ReturnType<typeof serializeObject>
|
|
67
94
|
type SerializedLinkValue = SerializedExpandedObject | SerializedExpandedObject[] | null
|
|
68
95
|
type SerializedExpandedObject = SerializedObject & {
|
|
@@ -445,6 +472,82 @@ export function registerObjectRoutes(app: Elysia, host: SixbHostView) {
|
|
|
445
472
|
},
|
|
446
473
|
}
|
|
447
474
|
)
|
|
475
|
+
.post(
|
|
476
|
+
"/api/objects/query/links",
|
|
477
|
+
async (context) => {
|
|
478
|
+
const { body, set } = context
|
|
479
|
+
try {
|
|
480
|
+
const parsed = ObjectQueryLinksRequestSchema.parse(body) as {
|
|
481
|
+
query: ObjectQuery
|
|
482
|
+
direction: "outgoing" | "incoming" | "both"
|
|
483
|
+
linkId?: string
|
|
484
|
+
includeObjects: boolean
|
|
485
|
+
pageSize: number
|
|
486
|
+
pageToken?: string
|
|
487
|
+
}
|
|
488
|
+
const result = await requireRequestSixb(context).objects.queryLinks(parsed)
|
|
489
|
+
|
|
490
|
+
return {
|
|
491
|
+
objects: result.objects.map(serializeObject),
|
|
492
|
+
links: result.links.map(serializeObjectLink),
|
|
493
|
+
hasMore: result.hasMore,
|
|
494
|
+
...(result.nextPageToken === undefined ? {} : { nextPageToken: result.nextPageToken }),
|
|
495
|
+
}
|
|
496
|
+
} catch (error) {
|
|
497
|
+
return handleObjectQueryError(error, set)
|
|
498
|
+
}
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
detail: {
|
|
502
|
+
summary: "Query object links",
|
|
503
|
+
tags: [OPENAPI_TAGS.links.name],
|
|
504
|
+
operationId: "queryObjectLinks",
|
|
505
|
+
security: bearerSecurityRequirement("queryObjectLinks"),
|
|
506
|
+
requestBody: {
|
|
507
|
+
required: true,
|
|
508
|
+
content: {
|
|
509
|
+
"application/json": {
|
|
510
|
+
schema: { $ref: "#/components/schemas/ObjectQueryLinksRequest" },
|
|
511
|
+
},
|
|
512
|
+
},
|
|
513
|
+
},
|
|
514
|
+
responses: {
|
|
515
|
+
200: {
|
|
516
|
+
description: "Response for status 200",
|
|
517
|
+
content: {
|
|
518
|
+
"application/json": {
|
|
519
|
+
schema: { $ref: "#/components/schemas/ObjectQueryLinksResponse" },
|
|
520
|
+
},
|
|
521
|
+
},
|
|
522
|
+
},
|
|
523
|
+
400: {
|
|
524
|
+
description: "Response for status 400",
|
|
525
|
+
content: {
|
|
526
|
+
"application/json": {
|
|
527
|
+
schema: { $ref: "#/components/schemas/ObjectQueryErrorResponse" },
|
|
528
|
+
},
|
|
529
|
+
},
|
|
530
|
+
},
|
|
531
|
+
403: {
|
|
532
|
+
description: "Response for status 403",
|
|
533
|
+
content: {
|
|
534
|
+
"application/json": {
|
|
535
|
+
schema: { $ref: "#/components/schemas/ErrorResponse" },
|
|
536
|
+
},
|
|
537
|
+
},
|
|
538
|
+
},
|
|
539
|
+
500: {
|
|
540
|
+
description: "Response for status 500",
|
|
541
|
+
content: {
|
|
542
|
+
"application/json": {
|
|
543
|
+
schema: { $ref: "#/components/schemas/ErrorResponse" },
|
|
544
|
+
},
|
|
545
|
+
},
|
|
546
|
+
},
|
|
547
|
+
},
|
|
548
|
+
},
|
|
549
|
+
}
|
|
550
|
+
)
|
|
448
551
|
.post(
|
|
449
552
|
"/api/objects/query/count",
|
|
450
553
|
async (context) => {
|
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
ObjectProjectionDefinition,
|
|
4
4
|
ProjectionDefinition,
|
|
5
5
|
SixbHostView,
|
|
6
|
+
SourceEditConflictResolution,
|
|
6
7
|
TelemetryProjectionDefinition,
|
|
7
8
|
} from "@sixb/core"
|
|
8
9
|
import type { ProjectionRunRecord } from "@sixb/core/storage"
|
|
@@ -81,14 +82,27 @@ function projectionCatalogIds(catalog: ViewableProjectionCatalog): string[] {
|
|
|
81
82
|
].map((projection) => projection.id)
|
|
82
83
|
}
|
|
83
84
|
|
|
85
|
+
type SerializedProjection<TProjection extends ProjectionDefinition> =
|
|
86
|
+
TProjection extends ObjectProjectionDefinition
|
|
87
|
+
? Omit<TProjection, "conflictResolution"> & {
|
|
88
|
+
conflictResolution: SourceEditConflictResolution
|
|
89
|
+
latestRun: SerializedProjectionRun | null
|
|
90
|
+
}
|
|
91
|
+
: TProjection & { latestRun: SerializedProjectionRun | null }
|
|
92
|
+
|
|
84
93
|
function serializeProjection<TProjection extends ProjectionDefinition>(
|
|
85
94
|
projection: TProjection,
|
|
86
95
|
latestRuns: ReadonlyMap<string, SerializedProjectionRun>
|
|
87
|
-
): TProjection
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
): SerializedProjection<TProjection> {
|
|
97
|
+
const latestRun = latestRuns.get(projection.id) ?? null
|
|
98
|
+
if (projection._tag === "ObjectProjectionDefinition") {
|
|
99
|
+
return {
|
|
100
|
+
...projection,
|
|
101
|
+
conflictResolution: projection.conflictResolution ?? { strategy: "editsWin" },
|
|
102
|
+
latestRun,
|
|
103
|
+
} as SerializedProjection<TProjection>
|
|
91
104
|
}
|
|
105
|
+
return { ...projection, latestRun } as SerializedProjection<TProjection>
|
|
92
106
|
}
|
|
93
107
|
|
|
94
108
|
function serializeProjectionCatalog(
|
package/src/routes/workflows.ts
CHANGED
|
@@ -145,6 +145,7 @@ function serializeWorkflowAgentExecutionSummary(execution: WorkflowAgentNodeRunV
|
|
|
145
145
|
modelId: execution.modelId,
|
|
146
146
|
finishReason: execution.finishReason,
|
|
147
147
|
usage: execution.usage,
|
|
148
|
+
cost: execution.cost,
|
|
148
149
|
startedAt: execution.startedAt ? toIsoString(execution.startedAt) : undefined,
|
|
149
150
|
completedAt: execution.completedAt ? toIsoString(execution.completedAt) : undefined,
|
|
150
151
|
}
|
|
@@ -157,11 +158,26 @@ function serializeWorkflowAgentExecution(execution: WorkflowAgentNodeRunView) {
|
|
|
157
158
|
prompt: execution.prompt,
|
|
158
159
|
trace: execution.trace,
|
|
159
160
|
diagnostics: execution.diagnostics,
|
|
161
|
+
failurePhase: workflowAgentFailurePhase(execution),
|
|
160
162
|
error: execution.error,
|
|
161
163
|
createdAt: toIsoString(execution.createdAt),
|
|
162
164
|
}
|
|
163
165
|
}
|
|
164
166
|
|
|
167
|
+
function workflowAgentFailurePhase(
|
|
168
|
+
execution: WorkflowAgentNodeRunView
|
|
169
|
+
): "agent-loop" | "structured-finalizer" | undefined {
|
|
170
|
+
const details = execution.error?.details
|
|
171
|
+
if (!isRecord(details)) return undefined
|
|
172
|
+
|
|
173
|
+
const phase = details.failurePhase
|
|
174
|
+
return phase === "agent-loop" || phase === "structured-finalizer" ? phase : undefined
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function isRecord(value: unknown): value is Readonly<Record<string, unknown>> {
|
|
178
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
179
|
+
}
|
|
180
|
+
|
|
165
181
|
function principalForExecution(sixb: Sixb<readonly OntologySource[]>): Principal {
|
|
166
182
|
return sixb.execution.requestedBy ?? SYSTEM_PRINCIPAL
|
|
167
183
|
}
|