@sixb/server 0.1.6 → 0.1.8
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/access-token-boundary.d.ts +3 -0
- package/dist/auth/access-token-boundary.d.ts.map +1 -1
- 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/auth/shared-access.d.ts +66 -0
- package/dist/auth/shared-access.d.ts.map +1 -0
- package/dist/files/content.d.ts +8 -0
- package/dist/files/content.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3402 -1693
- package/dist/index.js.map +35 -28
- package/dist/models/display.d.ts +22 -0
- package/dist/models/display.d.ts.map +1 -0
- package/dist/openapi/security.d.ts +15 -1
- package/dist/openapi/security.d.ts.map +1 -1
- package/dist/openapi/tags.d.ts +6 -2
- package/dist/openapi/tags.d.ts.map +1 -1
- package/dist/registerRoutes.d.ts +2 -0
- package/dist/registerRoutes.d.ts.map +1 -1
- 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 +100 -90
- 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 +143 -24
- package/dist/routes/auth.d.ts.map +1 -1
- package/dist/routes/connector-connection-runs.d.ts +8 -8
- package/dist/routes/connector-connections.d.ts +4 -4
- package/dist/routes/datasets.d.ts +5 -3
- package/dist/routes/datasets.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/logs.d.ts +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 +6 -1
- package/dist/routes/pipelines.d.ts.map +1 -1
- package/dist/routes/rules.d.ts +1 -1
- package/dist/routes/share-grants.d.ts +264 -0
- package/dist/routes/share-grants.d.ts.map +1 -0
- package/dist/routes/shared-access.d.ts +155 -0
- package/dist/routes/shared-access.d.ts.map +1 -0
- package/dist/routes/syncs.d.ts +3 -0
- package/dist/routes/syncs.d.ts.map +1 -1
- package/dist/routes/workflows.d.ts +58 -55
- package/dist/routes/workflows.d.ts.map +1 -1
- package/dist/routes/ws/logs.d.ts +4 -4
- package/dist/schemas/agents.d.ts +385 -230
- 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 +195 -112
- package/dist/schemas/auth.d.ts.map +1 -1
- package/dist/schemas/datasets.d.ts +28 -22
- package/dist/schemas/datasets.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/logs.d.ts +6 -6
- 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 +42 -6
- package/dist/schemas/pipelines.d.ts.map +1 -1
- package/dist/schemas/rules.d.ts +6 -6
- package/dist/schemas/share-grants.d.ts +518 -0
- package/dist/schemas/share-grants.d.ts.map +1 -0
- package/dist/schemas/shared-access.d.ts +42 -0
- package/dist/schemas/shared-access.d.ts.map +1 -0
- package/dist/schemas/syncs.d.ts +7 -0
- package/dist/schemas/syncs.d.ts.map +1 -1
- package/dist/schemas/workflows.d.ts +200 -210
- 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/dist/utils/http.d.ts +8 -4
- package/dist/utils/http.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/auth/access-token-boundary.ts +17 -2
- package/src/auth/public-routes.ts +23 -0
- package/src/auth/scope.ts +3 -2
- package/src/auth/shared-access.ts +376 -0
- package/src/files/content.ts +39 -6
- package/src/index.ts +1 -0
- package/src/models/display.ts +91 -0
- package/src/openapi/security.ts +20 -1
- package/src/openapi/tags.ts +4 -0
- package/src/registerRoutes.ts +6 -0
- package/src/routes/actions.ts +5 -10
- 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 +280 -1
- package/src/routes/models.ts +12 -4
- package/src/routes/share-grants.ts +238 -0
- package/src/routes/shared-access.ts +165 -0
- package/src/routes/workflows.ts +3 -5
- package/src/routes/ws/agents.ts +17 -6
- package/src/schemas/agents.ts +38 -50
- package/src/schemas/ai-accounting.ts +88 -19
- package/src/schemas/ai-limits.ts +116 -0
- package/src/schemas/auth.ts +32 -0
- package/src/schemas/datasets.ts +2 -1
- package/src/schemas/files.ts +1 -0
- package/src/schemas/models.ts +33 -5
- package/src/schemas/share-grants.ts +109 -0
- package/src/schemas/shared-access.ts +31 -0
- package/src/schemas/workflows.ts +0 -2
- package/src/server.ts +91 -1
- package/src/utils/http.ts +33 -2
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { z } from "zod"
|
|
2
|
+
import { AiMoneySchema } from "./ai-accounting"
|
|
3
|
+
|
|
4
|
+
const IsoDateSchema = z.string().datetime({ offset: true })
|
|
5
|
+
|
|
6
|
+
export const AiLimitSubjectSchema = z.discriminatedUnion("type", [
|
|
7
|
+
z.object({ type: z.literal("project") }),
|
|
8
|
+
z.object({ type: z.literal("group"), id: z.string().trim().min(1) }),
|
|
9
|
+
z.object({ type: z.literal("user"), id: z.string().trim().min(1) }),
|
|
10
|
+
z.object({ type: z.literal("serviceAccount"), id: z.string().trim().min(1) }),
|
|
11
|
+
])
|
|
12
|
+
|
|
13
|
+
export const AiLimitQuantitySchema = z.discriminatedUnion("meter", [
|
|
14
|
+
z.object({
|
|
15
|
+
meter: z.literal("tokens.total"),
|
|
16
|
+
amount: z.number().int().nonnegative().safe(),
|
|
17
|
+
}),
|
|
18
|
+
z.object({
|
|
19
|
+
meter: z.literal("cost.catalogEstimated"),
|
|
20
|
+
amount: AiMoneySchema.extend({ currency: z.literal("USD") }),
|
|
21
|
+
}),
|
|
22
|
+
])
|
|
23
|
+
|
|
24
|
+
export const AiLimitPolicySchema = z.object({
|
|
25
|
+
id: z.string(),
|
|
26
|
+
subject: AiLimitSubjectSchema,
|
|
27
|
+
limit: AiLimitQuantitySchema,
|
|
28
|
+
period: z.literal("calendarMonth"),
|
|
29
|
+
enabled: z.boolean(),
|
|
30
|
+
createdAt: IsoDateSchema,
|
|
31
|
+
updatedAt: IsoDateSchema,
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
export const AiLimitConsumptionSchema = z.object({
|
|
35
|
+
actual: AiLimitQuantitySchema,
|
|
36
|
+
reserved: AiLimitQuantitySchema,
|
|
37
|
+
unknown: AiLimitQuantitySchema,
|
|
38
|
+
remaining: AiLimitQuantitySchema,
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
export const AiLimitPolicyStatusSchema = z.object({
|
|
42
|
+
policy: AiLimitPolicySchema,
|
|
43
|
+
period: z.object({
|
|
44
|
+
kind: z.literal("calendarMonth"),
|
|
45
|
+
start: IsoDateSchema,
|
|
46
|
+
end: IsoDateSchema,
|
|
47
|
+
resetAt: IsoDateSchema,
|
|
48
|
+
}),
|
|
49
|
+
consumption: AiLimitConsumptionSchema,
|
|
50
|
+
accountingStatus: z.enum(["complete", "unavailable"]),
|
|
51
|
+
exhausted: z.boolean(),
|
|
52
|
+
orphaned: z.boolean(),
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
export const AiLimitCapabilitiesSchema = z.object({ manage: z.boolean() })
|
|
56
|
+
|
|
57
|
+
export const AiLimitSubjectOptionsResponseSchema = z.object({
|
|
58
|
+
groups: z.array(
|
|
59
|
+
z.object({
|
|
60
|
+
id: z.string(),
|
|
61
|
+
label: z.string().optional(),
|
|
62
|
+
description: z.string().optional(),
|
|
63
|
+
})
|
|
64
|
+
),
|
|
65
|
+
users: z.array(
|
|
66
|
+
z.object({
|
|
67
|
+
id: z.string(),
|
|
68
|
+
email: z.string(),
|
|
69
|
+
displayName: z.string().optional(),
|
|
70
|
+
status: z.enum(["active", "suspended"]),
|
|
71
|
+
})
|
|
72
|
+
),
|
|
73
|
+
serviceAccounts: z.array(
|
|
74
|
+
z.object({
|
|
75
|
+
id: z.string(),
|
|
76
|
+
name: z.string(),
|
|
77
|
+
description: z.string().optional(),
|
|
78
|
+
status: z.enum(["active", "suspended"]),
|
|
79
|
+
})
|
|
80
|
+
),
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
export const AiLimitListQuerySchema = z.object({
|
|
84
|
+
includeDisabled: z.enum(["true", "false"]).optional(),
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
export const AiLimitStatusQuerySchema = AiLimitListQuerySchema
|
|
88
|
+
|
|
89
|
+
export const AiLimitPolicyListResponseSchema = z.object({
|
|
90
|
+
items: z.array(AiLimitPolicySchema),
|
|
91
|
+
capabilities: AiLimitCapabilitiesSchema,
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
export const AiLimitPolicyStatusListResponseSchema = z.object({
|
|
95
|
+
items: z.array(AiLimitPolicyStatusSchema),
|
|
96
|
+
capabilities: AiLimitCapabilitiesSchema,
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
export const CreateAiLimitPolicyBodySchema = z.object({
|
|
100
|
+
subject: AiLimitSubjectSchema,
|
|
101
|
+
limit: AiLimitQuantitySchema,
|
|
102
|
+
enabled: z.boolean().optional(),
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
export const UpdateAiLimitPolicyBodySchema = z
|
|
106
|
+
.object({
|
|
107
|
+
limit: AiLimitQuantitySchema.optional(),
|
|
108
|
+
enabled: z.boolean().optional(),
|
|
109
|
+
})
|
|
110
|
+
.refine((value) => value.limit !== undefined || value.enabled !== undefined, {
|
|
111
|
+
message: "An AI limit update must change limit or enabled.",
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
export const AiLimitPolicyParamsSchema = z.object({
|
|
115
|
+
limitId: z.string().trim().min(1),
|
|
116
|
+
})
|
package/src/schemas/auth.ts
CHANGED
|
@@ -295,6 +295,38 @@ export const AuthSignOutResponseSchema = z.object({
|
|
|
295
295
|
success: z.boolean(),
|
|
296
296
|
})
|
|
297
297
|
|
|
298
|
+
export const CreateDeviceAuthorizationBodySchema = z.object({
|
|
299
|
+
clientName: z.string().trim().min(1).max(100),
|
|
300
|
+
tokenName: z.string().trim().min(1).max(100),
|
|
301
|
+
expiresIn: z.literal("90d").optional(),
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
export const CreateDeviceAuthorizationResponseSchema = z.object({
|
|
305
|
+
deviceCode: z.string(),
|
|
306
|
+
userCode: z.string(),
|
|
307
|
+
verificationUri: z.string(),
|
|
308
|
+
verificationUriComplete: z.string(),
|
|
309
|
+
expiresAt: z.string(),
|
|
310
|
+
interval: z.number(),
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
export const ExchangeDeviceAuthorizationBodySchema = z.object({
|
|
314
|
+
deviceCode: z.string().min(1),
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
export const ExchangeDeviceAuthorizationResponseSchema = z.union([
|
|
318
|
+
z.object({ status: z.literal("pending") }),
|
|
319
|
+
z.object({ status: z.literal("denied") }),
|
|
320
|
+
z.object({ status: z.literal("expired") }),
|
|
321
|
+
z.object({ status: z.literal("approved"), accessToken: z.string() }),
|
|
322
|
+
])
|
|
323
|
+
|
|
324
|
+
export const DeviceAuthorizationDecisionBodySchema = z.object({
|
|
325
|
+
userCode: z.string().trim().min(1),
|
|
326
|
+
decision: z.enum(["approve", "deny"]),
|
|
327
|
+
csrfToken: z.string().min(1),
|
|
328
|
+
})
|
|
329
|
+
|
|
298
330
|
export const AuthSessionSummarySchema = z.object({
|
|
299
331
|
id: z.string(),
|
|
300
332
|
audience: z.enum(["atlas", "app"]),
|
package/src/schemas/datasets.ts
CHANGED
|
@@ -43,6 +43,7 @@ export const DatasetDefinitionSchema = z.object({
|
|
|
43
43
|
id: z.string(),
|
|
44
44
|
description: z.string().optional(),
|
|
45
45
|
primaryKey: z.union([z.string(), z.array(z.string()).min(2)]).optional(),
|
|
46
|
+
sequenceBy: z.string().optional(),
|
|
46
47
|
partitionBy: z.array(z.string()).optional(),
|
|
47
48
|
schema: DatasetSchema,
|
|
48
49
|
})
|
|
@@ -53,7 +54,7 @@ export const DatasetVersionRefSchema = z.object({
|
|
|
53
54
|
})
|
|
54
55
|
|
|
55
56
|
export const DatasetProducerSchema = z.object({
|
|
56
|
-
kind: z.enum(["sync", "pipeline"]),
|
|
57
|
+
kind: z.enum(["sync", "pipeline", "ingest"]),
|
|
57
58
|
id: z.string().optional(),
|
|
58
59
|
runId: z.string().optional(),
|
|
59
60
|
})
|
package/src/schemas/files.ts
CHANGED
|
@@ -79,4 +79,5 @@ export const CompleteFileUploadBodySchema = z.object({
|
|
|
79
79
|
export const FileContentQuerySchema = z.object({
|
|
80
80
|
path: z.string().min(1),
|
|
81
81
|
disposition: z.enum(["inline", "attachment"]).optional(),
|
|
82
|
+
v: z.string().optional().describe("Client cache key; the route still resolves the current file"),
|
|
82
83
|
})
|
package/src/schemas/models.ts
CHANGED
|
@@ -1,15 +1,43 @@
|
|
|
1
|
+
import { MODEL_REASONING_LEVELS } from "@sixb/core/models"
|
|
1
2
|
import { z } from "zod"
|
|
2
3
|
|
|
3
|
-
export const
|
|
4
|
+
export const LanguageModelRefSchema = z.object({
|
|
5
|
+
provider: z.string().trim().min(1),
|
|
6
|
+
modelId: z.string().trim().min(1),
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
export const LanguageModelSchema = LanguageModelRefSchema.extend({
|
|
4
10
|
/**
|
|
5
|
-
* The
|
|
6
|
-
*
|
|
11
|
+
* The provider binding and model id the project configured. Together they identify the entry;
|
|
12
|
+
* there is no separate Sixb model id.
|
|
7
13
|
*/
|
|
8
|
-
provider: z.string(),
|
|
9
|
-
modelId: z.string(),
|
|
10
14
|
isDefault: z.boolean(),
|
|
15
|
+
name: z.string().min(1),
|
|
16
|
+
description: z.string().min(1).optional(),
|
|
17
|
+
publisher: z.object({
|
|
18
|
+
id: z.string().min(1),
|
|
19
|
+
name: z.string().min(1),
|
|
20
|
+
}),
|
|
21
|
+
via: z.string().min(1).optional(),
|
|
22
|
+
capabilities: z.object({
|
|
23
|
+
input: z.array(z.enum(["text", "image", "audio", "video", "pdf"])),
|
|
24
|
+
output: z.array(z.enum(["text", "image", "audio", "video", "pdf"])),
|
|
25
|
+
attachments: z.boolean().optional(),
|
|
26
|
+
reasoning: z.boolean().optional(),
|
|
27
|
+
tools: z.boolean().optional(),
|
|
28
|
+
structuredOutput: z.boolean().optional(),
|
|
29
|
+
contextWindowTokens: z.number().int().positive().optional(),
|
|
30
|
+
}),
|
|
31
|
+
reasoningLevels: z.array(z.enum(MODEL_REASONING_LEVELS)),
|
|
11
32
|
})
|
|
12
33
|
|
|
13
34
|
export const ModelCatalogSchema = z.object({
|
|
14
35
|
language: z.array(LanguageModelSchema),
|
|
15
36
|
})
|
|
37
|
+
|
|
38
|
+
export const ModelReasoningLevelSchema = z.enum(MODEL_REASONING_LEVELS)
|
|
39
|
+
|
|
40
|
+
export const ModelReasoningSchema = z.union([
|
|
41
|
+
ModelReasoningLevelSchema,
|
|
42
|
+
z.object({ budgetTokens: z.number().int().nonnegative() }).strict(),
|
|
43
|
+
])
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { z } from "zod"
|
|
2
|
+
|
|
3
|
+
const StoredIdentifierSchema = z.string().min(1).refine(isStoredIdentifier, {
|
|
4
|
+
message: "stored identifier must not be blank or contain NUL bytes",
|
|
5
|
+
})
|
|
6
|
+
const Rfc3339DateSchema = z.string().datetime({ offset: true })
|
|
7
|
+
const DestinationPathSchema = z.string().min(1).max(4_096)
|
|
8
|
+
|
|
9
|
+
const QueryBooleanSchema = z.preprocess((value) => {
|
|
10
|
+
if (value === "true" || value === true) return true
|
|
11
|
+
if (value === "false" || value === false) return false
|
|
12
|
+
return value
|
|
13
|
+
}, z.boolean())
|
|
14
|
+
|
|
15
|
+
const ShareGrantListLimitSchema = z.preprocess(
|
|
16
|
+
parseUnsignedQueryInteger,
|
|
17
|
+
z.number().int().min(1).max(200)
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
const ShareGrantListOffsetSchema = z.preprocess(
|
|
21
|
+
parseUnsignedQueryInteger,
|
|
22
|
+
z.number().int().min(0).max(Number.MAX_SAFE_INTEGER)
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
function parseUnsignedQueryInteger(value: unknown): unknown {
|
|
26
|
+
if (typeof value !== "string" || !/^\d+$/.test(value)) return value
|
|
27
|
+
const parsed = Number(value)
|
|
28
|
+
return Number.isSafeInteger(parsed) ? parsed : value
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const ShareGrantTargetSchema = z.object({
|
|
32
|
+
objectTypeId: StoredIdentifierSchema,
|
|
33
|
+
primaryId: StoredIdentifierSchema,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const ShareGrantTargetInputSchema = z.object({
|
|
37
|
+
objectTypeId: StoredIdentifierSchema,
|
|
38
|
+
primaryId: z.string().min(1).refine(isStoredIdentifier, {
|
|
39
|
+
message: "primaryId must not be blank or contain NUL bytes",
|
|
40
|
+
}),
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const AuthorizablePrincipalSchema = z.object({
|
|
44
|
+
type: z.enum(["user", "serviceAccount"]),
|
|
45
|
+
id: StoredIdentifierSchema,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const PrincipalSchema = z.object({
|
|
49
|
+
type: z.enum(["user", "serviceAccount", "system"]),
|
|
50
|
+
id: StoredIdentifierSchema,
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
export const SharedAccessGrantSchema = z.object({
|
|
54
|
+
id: StoredIdentifierSchema,
|
|
55
|
+
definitionId: StoredIdentifierSchema,
|
|
56
|
+
target: ShareGrantTargetSchema,
|
|
57
|
+
issuedBy: AuthorizablePrincipalSchema,
|
|
58
|
+
destinationPath: DestinationPathSchema,
|
|
59
|
+
createdAt: Rfc3339DateSchema,
|
|
60
|
+
expiresAt: Rfc3339DateSchema,
|
|
61
|
+
revokedAt: Rfc3339DateSchema.optional(),
|
|
62
|
+
revokedBy: PrincipalSchema.optional(),
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
export const IssueSharedAccessGrantBodySchema = z.object({
|
|
66
|
+
definitionId: StoredIdentifierSchema,
|
|
67
|
+
target: ShareGrantTargetInputSchema,
|
|
68
|
+
destinationPath: DestinationPathSchema,
|
|
69
|
+
expiresAt: Rfc3339DateSchema,
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
export const IssueSharedAccessGrantResponseSchema = z.object({
|
|
73
|
+
grant: SharedAccessGrantSchema,
|
|
74
|
+
/** Same-origin URL. The bearer secret exists only in its fragment. */
|
|
75
|
+
url: z.string().startsWith("/shared/"),
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
export const ListSharedAccessGrantsQuerySchema = z.object({
|
|
79
|
+
definitionId: StoredIdentifierSchema,
|
|
80
|
+
primaryId: z
|
|
81
|
+
.string()
|
|
82
|
+
.min(1)
|
|
83
|
+
.refine(isStoredIdentifier, {
|
|
84
|
+
message: "primaryId must not be blank or contain NUL bytes",
|
|
85
|
+
})
|
|
86
|
+
.optional(),
|
|
87
|
+
includeRevoked: QueryBooleanSchema.optional(),
|
|
88
|
+
includeExpired: QueryBooleanSchema.optional(),
|
|
89
|
+
limit: ShareGrantListLimitSchema.optional(),
|
|
90
|
+
offset: ShareGrantListOffsetSchema.optional(),
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
export const ListSharedAccessGrantsResponseSchema = z.object({
|
|
94
|
+
grants: z.array(SharedAccessGrantSchema),
|
|
95
|
+
hasMore: z.boolean(),
|
|
96
|
+
total: z.number().int().nonnegative(),
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
export const SharedAccessGrantIdParamsSchema = z.object({
|
|
100
|
+
grantId: StoredIdentifierSchema,
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
export const RevokeSharedAccessGrantResponseSchema = z.object({
|
|
104
|
+
grant: SharedAccessGrantSchema,
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
function isStoredIdentifier(value: string): boolean {
|
|
108
|
+
return value.trim().length > 0 && !value.includes("\0")
|
|
109
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from "zod"
|
|
2
|
+
|
|
3
|
+
const StoredIdentifierSchema = z
|
|
4
|
+
.string()
|
|
5
|
+
.min(1)
|
|
6
|
+
.max(128)
|
|
7
|
+
.refine((value) => value.trim() === value && !value.includes("\0"), {
|
|
8
|
+
message: "stored identifier must not be blank or contain NUL bytes",
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
const Rfc3339DateSchema = z.string().datetime({ offset: true })
|
|
12
|
+
|
|
13
|
+
export const SharedAccessGrantParamsSchema = z.object({
|
|
14
|
+
grantId: StoredIdentifierSchema,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export const ExchangeSharedAccessBodySchema = z.object({
|
|
18
|
+
secret: z.string().regex(/^[A-Za-z0-9_-]{43}$/),
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
export const SharedAccessSessionResponseSchema = z.object({
|
|
22
|
+
grantId: StoredIdentifierSchema,
|
|
23
|
+
destinationPath: z.string().min(1).max(4_096),
|
|
24
|
+
expiresAt: Rfc3339DateSchema,
|
|
25
|
+
absoluteExpiresAt: Rfc3339DateSchema,
|
|
26
|
+
csrfToken: z.string().regex(/^[A-Za-z0-9_-]{43}$/),
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
export const SharedAccessSignOutResponseSchema = z.object({
|
|
30
|
+
signedOut: z.literal(true),
|
|
31
|
+
})
|
package/src/schemas/workflows.ts
CHANGED
|
@@ -119,7 +119,6 @@ const WorkflowNodeSchema = z.union([
|
|
|
119
119
|
type: z.literal("agent"),
|
|
120
120
|
id: z.string(),
|
|
121
121
|
key: z.string(),
|
|
122
|
-
agentId: z.string(),
|
|
123
122
|
input: WorkflowIOSnapshotSchema,
|
|
124
123
|
output: WorkflowIOSnapshotSchema,
|
|
125
124
|
}),
|
|
@@ -143,7 +142,6 @@ export const WorkflowRunDetailSchema = WorkflowRunSummarySchema.extend({
|
|
|
143
142
|
})
|
|
144
143
|
|
|
145
144
|
export const WorkflowAgentNodeExecutionSummarySchema = z.object({
|
|
146
|
-
agentId: z.string(),
|
|
147
145
|
status: z.enum(["queued", "running", "succeeded", "failed", "cancelled"]),
|
|
148
146
|
attempt: z.number().int().nonnegative(),
|
|
149
147
|
modelId: z.string().optional(),
|
package/src/server.ts
CHANGED
|
@@ -30,11 +30,18 @@ import { ServerAuthGuard } from "./auth/guard"
|
|
|
30
30
|
import { consumeInternalRequestAuthState } from "./auth/scope"
|
|
31
31
|
import { SESSION_ACTIVITY_HEADER_NAME } from "./auth/session-activity"
|
|
32
32
|
import { createSessionRenewalCookieHeaders } from "./auth/session-cookies"
|
|
33
|
+
import {
|
|
34
|
+
SHARED_ACCESS_GRANT_HEADER_NAME,
|
|
35
|
+
SharedAccessBoundary,
|
|
36
|
+
type SixbSharedAccessOptions,
|
|
37
|
+
} from "./auth/shared-access"
|
|
33
38
|
import {
|
|
34
39
|
SIXB_BEARER_SECURITY_SCHEME,
|
|
35
40
|
SIXB_BEARER_SECURITY_SCHEME_ID,
|
|
36
41
|
SIXB_CSRF_SECURITY_SCHEME,
|
|
37
42
|
SIXB_CSRF_SECURITY_SCHEME_ID,
|
|
43
|
+
SIXB_SHARED_GRANT_SECURITY_SCHEME,
|
|
44
|
+
SIXB_SHARED_GRANT_SECURITY_SCHEME_ID,
|
|
38
45
|
} from "./openapi/security"
|
|
39
46
|
import { OPENAPI_TAG_METADATA } from "./openapi/tags"
|
|
40
47
|
import { registerHttpRoutes } from "./registerRoutes"
|
|
@@ -52,6 +59,8 @@ export interface SixbServerOptions {
|
|
|
52
59
|
browser: SixbApiBrowserPolicy
|
|
53
60
|
/** Optional custom-app auth bundle mounted under the API's `/auth` routes. */
|
|
54
61
|
authExperience?: SixbAuthExperienceOptions
|
|
62
|
+
/** Optional server limits for short-lived shared-access sessions. */
|
|
63
|
+
sharedAccess?: SixbSharedAccessOptions
|
|
55
64
|
}
|
|
56
65
|
|
|
57
66
|
export function createSixbServer(options: SixbServerOptions): SixbServer {
|
|
@@ -67,6 +76,7 @@ export class SixbServer {
|
|
|
67
76
|
private readonly authContextResolver: ResolveRequestAuthContext
|
|
68
77
|
private readonly authRedirectContextResolver: ResolveAuthRedirectContext
|
|
69
78
|
private readonly authExperience?: SixbAuthExperienceOptions
|
|
79
|
+
private readonly sharedAccessOptions: SixbSharedAccessOptions
|
|
70
80
|
private app: SixbApp | null = null
|
|
71
81
|
private bunServer: ReturnType<typeof Bun.serve> | null = null
|
|
72
82
|
private maintenance: OntologyMaintenanceHandle | null = null
|
|
@@ -82,6 +92,7 @@ export class SixbServer {
|
|
|
82
92
|
this.apiBrowserPolicy
|
|
83
93
|
)
|
|
84
94
|
this.authExperience = options.authExperience
|
|
95
|
+
this.sharedAccessOptions = options.sharedAccess ?? {}
|
|
85
96
|
}
|
|
86
97
|
|
|
87
98
|
getHost(): SixbHostView {
|
|
@@ -126,6 +137,10 @@ export class SixbServer {
|
|
|
126
137
|
return this.authExperience
|
|
127
138
|
}
|
|
128
139
|
|
|
140
|
+
getSharedAccessOptions(): SixbSharedAccessOptions {
|
|
141
|
+
return this.sharedAccessOptions
|
|
142
|
+
}
|
|
143
|
+
|
|
129
144
|
async start(): Promise<void> {
|
|
130
145
|
if (this.app !== null || this.bunServer !== null || this.maintenance !== null) {
|
|
131
146
|
throw new Error("[SixbServer] Server is already running.")
|
|
@@ -179,6 +194,11 @@ export function createSixbApi(server: SixbServer) {
|
|
|
179
194
|
host,
|
|
180
195
|
resolveAuthContext: (request) => server.resolveAuthContext(request),
|
|
181
196
|
})
|
|
197
|
+
const sharedAccess = new SharedAccessBoundary(host, server.getSharedAccessOptions())
|
|
198
|
+
const preparedSharedAccess = new WeakMap<
|
|
199
|
+
Request,
|
|
200
|
+
Awaited<ReturnType<SharedAccessBoundary["resolveRequest"]>>
|
|
201
|
+
>()
|
|
182
202
|
guard.assertCanServeHttp({ production: process.env.NODE_ENV === "production" })
|
|
183
203
|
const apiBrowserPolicy = server.getApiBrowserPolicy()
|
|
184
204
|
|
|
@@ -200,21 +220,65 @@ export function createSixbApi(server: SixbServer) {
|
|
|
200
220
|
"content-type",
|
|
201
221
|
CSRF_HEADER_NAME,
|
|
202
222
|
SESSION_ACTIVITY_HEADER_NAME,
|
|
223
|
+
SHARED_ACCESS_GRANT_HEADER_NAME,
|
|
203
224
|
],
|
|
204
225
|
exposeHeaders: [CSRF_TOKEN_RESPONSE_HEADER_NAME],
|
|
205
226
|
maxAge: 600,
|
|
206
227
|
})
|
|
207
228
|
)
|
|
229
|
+
app.onRequest(async ({ request, set }) => {
|
|
230
|
+
// Resolve Share intent before Elysia parses route inputs. Otherwise an unsupported route or an
|
|
231
|
+
// invalid shared session could escape through a route-specific 4xx before this boundary ran.
|
|
232
|
+
// CORS is registered first so allowed app origins can read these generic boundary responses.
|
|
233
|
+
const shared = await sharedAccess.resolveRequest(request)
|
|
234
|
+
preparedSharedAccess.set(request, shared)
|
|
235
|
+
if (shared.kind === "allow") {
|
|
236
|
+
// Route parsing happens after onRequest but before derive. Set this here so parse/schema
|
|
237
|
+
// failures from an authenticated shared request cannot become cacheable.
|
|
238
|
+
setResponseHeader(set, "cache-control", "no-store")
|
|
239
|
+
}
|
|
240
|
+
return shared.kind === "deny" ? shared.response : undefined
|
|
241
|
+
})
|
|
208
242
|
|
|
209
243
|
// Resolve authentication and bind one execution SDK at the request boundary. Protected routes
|
|
210
244
|
// never choose between a principal SDK and the ambient runtime themselves.
|
|
211
245
|
app
|
|
212
246
|
.derive(async ({ request }) => {
|
|
247
|
+
const shared =
|
|
248
|
+
preparedSharedAccess.get(request) ?? (await sharedAccess.resolveRequest(request))
|
|
249
|
+
preparedSharedAccess.delete(request)
|
|
250
|
+
if (shared.kind === "deny") {
|
|
251
|
+
return {
|
|
252
|
+
auth: { kind: "deny" as const, response: shared.response },
|
|
253
|
+
sharedAccessCookies: null,
|
|
254
|
+
sixb: null,
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (shared.kind === "allow") {
|
|
258
|
+
return {
|
|
259
|
+
auth: { kind: "allow" as const, session: null },
|
|
260
|
+
sharedAccessCookies: shared.cookies,
|
|
261
|
+
sixb: bindRequestExecution(host, {
|
|
262
|
+
request,
|
|
263
|
+
authorization: {
|
|
264
|
+
type: "delegated",
|
|
265
|
+
access: shared.context.access,
|
|
266
|
+
delegation: {
|
|
267
|
+
kind: "share",
|
|
268
|
+
grantId: shared.context.grantId,
|
|
269
|
+
sessionId: shared.context.sessionId,
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
}),
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
213
276
|
const internalAuthState = consumeInternalRequestAuthState(request)
|
|
214
277
|
if (internalAuthState) {
|
|
215
278
|
const { authorization, ...agentState } = internalAuthState
|
|
216
279
|
return {
|
|
217
280
|
auth: { kind: "allow" as const, session: null },
|
|
281
|
+
sharedAccessCookies: null,
|
|
218
282
|
...agentState,
|
|
219
283
|
sixb: bindRequestExecution(host, {
|
|
220
284
|
request,
|
|
@@ -227,6 +291,7 @@ export function createSixbApi(server: SixbServer) {
|
|
|
227
291
|
if (auth.kind === "deny" || !auth.session?.authenticated) {
|
|
228
292
|
return {
|
|
229
293
|
auth,
|
|
294
|
+
sharedAccessCookies: null,
|
|
230
295
|
sixb:
|
|
231
296
|
auth.kind === "allow" && !guard.isAuthEnabled()
|
|
232
297
|
? bindRequestExecution(host, {
|
|
@@ -244,6 +309,7 @@ export function createSixbApi(server: SixbServer) {
|
|
|
244
309
|
: { type: "accessToken" as const, id: auth.session.accessToken.id }
|
|
245
310
|
return {
|
|
246
311
|
auth,
|
|
312
|
+
sharedAccessCookies: null,
|
|
247
313
|
sixb: bindRequestExecution(host, {
|
|
248
314
|
request,
|
|
249
315
|
authorization: { type: "principal", context: authz, credential },
|
|
@@ -251,7 +317,29 @@ export function createSixbApi(server: SixbServer) {
|
|
|
251
317
|
}
|
|
252
318
|
})
|
|
253
319
|
.onBeforeHandle(({ auth }) => (auth.kind === "deny" ? auth.response : undefined))
|
|
254
|
-
.mapResponse(({ auth, request, set }) => {
|
|
320
|
+
.mapResponse(({ auth, request, responseValue, set, sharedAccessCookies }) => {
|
|
321
|
+
if (sharedAccessCookies) {
|
|
322
|
+
if (sharedAccessCookies.setCookies.length > 0) {
|
|
323
|
+
appendSetCookieHeaders(set, sharedAccessCookies.setCookies)
|
|
324
|
+
}
|
|
325
|
+
setResponseHeader(set, CSRF_TOKEN_RESPONSE_HEADER_NAME, sharedAccessCookies.csrfToken)
|
|
326
|
+
setResponseHeader(set, "cache-control", "no-store")
|
|
327
|
+
|
|
328
|
+
// Elysia intentionally gives headers from an explicit Response precedence over `set`.
|
|
329
|
+
// File reads carry their normal long-lived private cache policy on such a Response, so
|
|
330
|
+
// rebuild it with `no-store` at the same boundary that selected the Share authority.
|
|
331
|
+
if (responseValue instanceof Response) {
|
|
332
|
+
const headers = new Headers(responseValue.headers)
|
|
333
|
+
headers.set("cache-control", "no-store")
|
|
334
|
+
return new Response(responseValue.body, {
|
|
335
|
+
status: responseValue.status,
|
|
336
|
+
statusText: responseValue.statusText,
|
|
337
|
+
headers,
|
|
338
|
+
})
|
|
339
|
+
}
|
|
340
|
+
return
|
|
341
|
+
}
|
|
342
|
+
|
|
255
343
|
if (
|
|
256
344
|
!auth ||
|
|
257
345
|
auth.kind !== "allow" ||
|
|
@@ -288,6 +376,7 @@ export function createSixbApi(server: SixbServer) {
|
|
|
288
376
|
securitySchemes: {
|
|
289
377
|
[SIXB_CSRF_SECURITY_SCHEME_ID]: SIXB_CSRF_SECURITY_SCHEME,
|
|
290
378
|
[SIXB_BEARER_SECURITY_SCHEME_ID]: SIXB_BEARER_SECURITY_SCHEME,
|
|
379
|
+
[SIXB_SHARED_GRANT_SECURITY_SCHEME_ID]: SIXB_SHARED_GRANT_SECURITY_SCHEME,
|
|
291
380
|
},
|
|
292
381
|
schemas: ObjectQueryOpenApiSchemas,
|
|
293
382
|
},
|
|
@@ -318,6 +407,7 @@ export function createSixbApi(server: SixbServer) {
|
|
|
318
407
|
server.resolveInvitationRedirectContext(request, input),
|
|
319
408
|
})
|
|
320
409
|
registerHttpRoutes(app, host, {
|
|
410
|
+
sharedAccess,
|
|
321
411
|
connectorConnections: {
|
|
322
412
|
resolveReturnTo: (request, returnTo) => {
|
|
323
413
|
const authContext = server.resolveAuthContext(request)
|
package/src/utils/http.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
AuthorizationError,
|
|
3
3
|
OntologyNotFoundError,
|
|
4
4
|
OntologyValidationError,
|
|
5
|
+
type ReadonlyJsonValue,
|
|
5
6
|
type SixbErrorCode,
|
|
6
7
|
} from "@sixb/core"
|
|
7
8
|
import { isSixbError } from "@sixb/core/internal/errors"
|
|
@@ -28,6 +29,13 @@ const HTTP_STATUS_BY_ERROR_CODE: Partial<Record<SixbErrorCode, number>> = {
|
|
|
28
29
|
"connector.revocation_pending": 409,
|
|
29
30
|
"dataset.not_found": 404,
|
|
30
31
|
"dataset.version_not_found": 404,
|
|
32
|
+
"ai.usage_limit_exceeded": 429,
|
|
33
|
+
"ai.usage_limit_unavailable": 429,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface RouteResponseSet {
|
|
37
|
+
status?: number | string
|
|
38
|
+
headers?: unknown
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
export function toIsoString(value: Date): string {
|
|
@@ -79,14 +87,22 @@ export function unconfiguredStorageResponse(
|
|
|
79
87
|
|
|
80
88
|
export function handleRouteError(
|
|
81
89
|
error: unknown,
|
|
82
|
-
set:
|
|
90
|
+
set: RouteResponseSet
|
|
83
91
|
): {
|
|
84
92
|
error: string
|
|
85
93
|
code?: SixbErrorCode
|
|
94
|
+
details?: ReadonlyJsonValue
|
|
86
95
|
} {
|
|
87
96
|
if (isSixbError(error)) {
|
|
88
97
|
set.status = HTTP_STATUS_BY_ERROR_CODE[error.code] ?? 500
|
|
89
|
-
|
|
98
|
+
if (error.code === "ai.usage_limit_exceeded") setRetryAfterFromDetails(set, error.details)
|
|
99
|
+
const exposesDetails =
|
|
100
|
+
error.code === "ai.usage_limit_exceeded" || error.code === "ai.usage_limit_unavailable"
|
|
101
|
+
return {
|
|
102
|
+
error: error.message,
|
|
103
|
+
code: error.code,
|
|
104
|
+
...(!exposesDetails || error.details === undefined ? {} : { details: error.details }),
|
|
105
|
+
}
|
|
90
106
|
}
|
|
91
107
|
|
|
92
108
|
if (error instanceof AuthorizationError) {
|
|
@@ -123,6 +139,21 @@ export function handleRouteError(
|
|
|
123
139
|
return { error: message }
|
|
124
140
|
}
|
|
125
141
|
|
|
142
|
+
function setRetryAfterFromDetails(set: RouteResponseSet, details: ReadonlyJsonValue | undefined) {
|
|
143
|
+
if (typeof details !== "object" || details === null || Array.isArray(details)) return
|
|
144
|
+
const resetAt = (details as Readonly<Record<string, ReadonlyJsonValue>>).resetAt
|
|
145
|
+
if (typeof resetAt !== "string") return
|
|
146
|
+
const resetTime = Date.parse(resetAt)
|
|
147
|
+
if (!Number.isFinite(resetTime)) return
|
|
148
|
+
const seconds = String(Math.max(0, Math.ceil((resetTime - Date.now()) / 1_000)))
|
|
149
|
+
const headers =
|
|
150
|
+
typeof set.headers === "object" && set.headers !== null
|
|
151
|
+
? (set.headers as Record<string, unknown>)
|
|
152
|
+
: {}
|
|
153
|
+
headers["Retry-After"] = seconds
|
|
154
|
+
set.headers = headers
|
|
155
|
+
}
|
|
156
|
+
|
|
126
157
|
function fileUploadSessionErrorStatus(reason: FileUploadSessionErrorReason): number {
|
|
127
158
|
switch (reason) {
|
|
128
159
|
case "not_found":
|