@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
package/src/schemas/agents.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { AGENT_REASONING_LEVELS, MAX_AGENT_CONTEXT_ENTRIES } from "@sixb/core"
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
AGENT_RUN_DIAGNOSTIC_CODES,
|
|
4
|
+
AGENT_RUN_FAILURE_CODES,
|
|
5
|
+
AGENT_RUN_FINISH_REASONS,
|
|
6
|
+
type AgentRunFailureCode,
|
|
7
|
+
type SixbFailure,
|
|
8
|
+
} from "@sixb/core/storage"
|
|
3
9
|
import { z } from "zod"
|
|
4
|
-
import {
|
|
10
|
+
import { AiCostSummarySchema } from "./ai-accounting"
|
|
11
|
+
import { AiUsageSummarySchema } from "./ai-usage"
|
|
12
|
+
import { JsonValueSchema, sixbFailureSchema } from "./common"
|
|
5
13
|
import { FileRefSchema } from "./files"
|
|
6
14
|
|
|
15
|
+
export const AgentRunFailureSchema: z.ZodType<SixbFailure<AgentRunFailureCode>> =
|
|
16
|
+
sixbFailureSchema(AGENT_RUN_FAILURE_CODES)
|
|
17
|
+
|
|
7
18
|
export const AgentIdParamsSchema = z.object({
|
|
8
19
|
agentId: z.string().min(1),
|
|
9
20
|
})
|
|
@@ -25,6 +36,11 @@ export const AgentPrincipalSchema = z.object({
|
|
|
25
36
|
id: z.string().min(1),
|
|
26
37
|
})
|
|
27
38
|
|
|
39
|
+
export const AgentAuthorizablePrincipalSchema = z.object({
|
|
40
|
+
type: z.enum(["user", "serviceAccount"]),
|
|
41
|
+
id: z.string().min(1),
|
|
42
|
+
})
|
|
43
|
+
|
|
28
44
|
export const AgentObjectContextSchema = z.object({
|
|
29
45
|
kind: z.literal("object"),
|
|
30
46
|
ref: z.object({
|
|
@@ -228,23 +244,7 @@ export const AgentRunStatusSchema = z.enum([
|
|
|
228
244
|
"cancelled",
|
|
229
245
|
])
|
|
230
246
|
|
|
231
|
-
export const AgentRunFinishReasonSchema = z.enum(
|
|
232
|
-
"stop",
|
|
233
|
-
"length",
|
|
234
|
-
"content-filter",
|
|
235
|
-
"tool-calls",
|
|
236
|
-
"error",
|
|
237
|
-
"other",
|
|
238
|
-
"unknown",
|
|
239
|
-
])
|
|
240
|
-
|
|
241
|
-
export const AgentRunUsageSchema = z.object({
|
|
242
|
-
inputTokens: z.number().optional(),
|
|
243
|
-
outputTokens: z.number().optional(),
|
|
244
|
-
totalTokens: z.number().optional(),
|
|
245
|
-
reasoningTokens: z.number().optional(),
|
|
246
|
-
cachedInputTokens: z.number().optional(),
|
|
247
|
-
})
|
|
247
|
+
export const AgentRunFinishReasonSchema = z.enum(AGENT_RUN_FINISH_REASONS)
|
|
248
248
|
|
|
249
249
|
export const AgentRunSchema = z.object({
|
|
250
250
|
id: z.string(),
|
|
@@ -252,14 +252,14 @@ export const AgentRunSchema = z.object({
|
|
|
252
252
|
threadId: z.string(),
|
|
253
253
|
agentId: z.string(),
|
|
254
254
|
triggerMessageId: z.string(),
|
|
255
|
-
|
|
256
|
-
executionPrincipal: AgentPrincipalSchema.optional(),
|
|
255
|
+
requestedBy: AgentAuthorizablePrincipalSchema.optional(),
|
|
257
256
|
status: AgentRunStatusSchema,
|
|
258
257
|
modelId: z.string().optional(),
|
|
259
258
|
finishReason: AgentRunFinishReasonSchema.optional(),
|
|
260
|
-
usage:
|
|
259
|
+
usage: AiUsageSummarySchema.optional(),
|
|
260
|
+
cost: AiCostSummarySchema.optional(),
|
|
261
261
|
diagnostics: z.array(AgentRunDiagnosticSchema).optional(),
|
|
262
|
-
error:
|
|
262
|
+
error: AgentRunFailureSchema.optional(),
|
|
263
263
|
attempt: z.number(),
|
|
264
264
|
streamId: z.string(),
|
|
265
265
|
createdAt: z.string(),
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { z } from "zod"
|
|
2
|
+
import { AiUsageSummarySchema } from "./ai-usage"
|
|
3
|
+
|
|
4
|
+
const IntegerStringSchema = z.string().regex(/^\d+$/)
|
|
5
|
+
const IsoDateSchema = z.string().datetime({ offset: true })
|
|
6
|
+
|
|
7
|
+
export const AiAccountingBucketSchema = z.enum(["hour", "day", "week"])
|
|
8
|
+
export const AiValuationStatusSchema = z.enum(["rated", "unpriceable", "unvalued"])
|
|
9
|
+
|
|
10
|
+
export const AiAccountingRangeQuerySchema = z.object({
|
|
11
|
+
from: IsoDateSchema,
|
|
12
|
+
to: IsoDateSchema,
|
|
13
|
+
providerId: z.string().trim().min(1).optional(),
|
|
14
|
+
modelId: z.string().trim().min(1).optional(),
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export const AiAccountingOverviewQuerySchema = AiAccountingRangeQuerySchema.extend({
|
|
18
|
+
bucket: AiAccountingBucketSchema,
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
export const AiModelCallAccountingListQuerySchema = AiAccountingRangeQuerySchema.extend({
|
|
22
|
+
executionId: z.string().trim().min(1).optional(),
|
|
23
|
+
valuationStatus: AiValuationStatusSchema.optional(),
|
|
24
|
+
limit: IntegerStringSchema.optional(),
|
|
25
|
+
offset: IntegerStringSchema.optional(),
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
export const AiMoneySchema = z.object({
|
|
29
|
+
currency: z.string().regex(/^[A-Z]{3}$/),
|
|
30
|
+
amountNanos: IntegerStringSchema,
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
export const AiCostSummarySchema = z.object({
|
|
34
|
+
amounts: z.array(AiMoneySchema),
|
|
35
|
+
ratedCallCount: z.number().int().nonnegative(),
|
|
36
|
+
unpriceableCallCount: z.number().int().nonnegative(),
|
|
37
|
+
unvaluedCallCount: z.number().int().nonnegative(),
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const AiAccountingAggregateSchema = z.object({
|
|
41
|
+
modelCallCount: z.number().int().nonnegative(),
|
|
42
|
+
usage: AiUsageSummarySchema,
|
|
43
|
+
costs: AiCostSummarySchema,
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
export const AiAccountingOverviewResponseSchema = z.object({
|
|
47
|
+
range: z.object({ from: IsoDateSchema, to: IsoDateSchema }),
|
|
48
|
+
bucket: AiAccountingBucketSchema,
|
|
49
|
+
totals: AiAccountingAggregateSchema,
|
|
50
|
+
series: z.array(
|
|
51
|
+
AiAccountingAggregateSchema.extend({
|
|
52
|
+
start: IsoDateSchema,
|
|
53
|
+
end: IsoDateSchema,
|
|
54
|
+
})
|
|
55
|
+
),
|
|
56
|
+
models: z.array(
|
|
57
|
+
AiAccountingAggregateSchema.extend({
|
|
58
|
+
providerId: z.string(),
|
|
59
|
+
modelId: z.string(),
|
|
60
|
+
})
|
|
61
|
+
),
|
|
62
|
+
agents: z.array(
|
|
63
|
+
AiAccountingAggregateSchema.extend({
|
|
64
|
+
agentId: z.string(),
|
|
65
|
+
})
|
|
66
|
+
),
|
|
67
|
+
workflows: z.array(
|
|
68
|
+
AiAccountingAggregateSchema.extend({
|
|
69
|
+
workflowId: z.string(),
|
|
70
|
+
})
|
|
71
|
+
),
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
export const AiPricingContextSchema = z.object({
|
|
75
|
+
serviceTier: z.string().optional(),
|
|
76
|
+
batch: z.boolean().optional(),
|
|
77
|
+
region: z.string().optional(),
|
|
78
|
+
inferenceGeo: z.string().optional(),
|
|
79
|
+
routedProviderId: z.string().optional(),
|
|
80
|
+
deploymentId: z.string().optional(),
|
|
81
|
+
inferenceProfileId: z.string().optional(),
|
|
82
|
+
cacheWriteTtlSeconds: z.number().int().positive().optional(),
|
|
83
|
+
mode: z.string().optional(),
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
const AiCostComponentSchema = z.object({
|
|
87
|
+
meter: z.enum([
|
|
88
|
+
"tokens.input.total",
|
|
89
|
+
"tokens.input.uncached",
|
|
90
|
+
"tokens.input.cacheRead",
|
|
91
|
+
"tokens.input.cacheWrite",
|
|
92
|
+
"tokens.output.total",
|
|
93
|
+
"tokens.output.text",
|
|
94
|
+
"tokens.output.reasoning",
|
|
95
|
+
]),
|
|
96
|
+
quantity: IntegerStringSchema,
|
|
97
|
+
rateAmountNanosPerMillion: IntegerStringSchema,
|
|
98
|
+
chargeAmountNanos: IntegerStringSchema,
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
const AiBillingIdentitySchema = z.object({
|
|
102
|
+
providerId: z.string(),
|
|
103
|
+
modelId: z.string(),
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
const AiPriceSourceSchema = z.object({
|
|
107
|
+
sourceId: z.string(),
|
|
108
|
+
sourceEntryId: z.string(),
|
|
109
|
+
sourceVersion: z.string(),
|
|
110
|
+
sourceUrl: z.string().url(),
|
|
111
|
+
observedAt: IsoDateSchema,
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
const AiModelCallCostSchema = z.discriminatedUnion("status", [
|
|
115
|
+
z.object({
|
|
116
|
+
status: z.literal("rated"),
|
|
117
|
+
billingIdentity: AiBillingIdentitySchema,
|
|
118
|
+
pricingContext: AiPricingContextSchema,
|
|
119
|
+
priceSource: AiPriceSourceSchema,
|
|
120
|
+
money: AiMoneySchema,
|
|
121
|
+
components: z.array(AiCostComponentSchema),
|
|
122
|
+
ratedAt: IsoDateSchema,
|
|
123
|
+
}),
|
|
124
|
+
z.object({
|
|
125
|
+
status: z.literal("unpriceable"),
|
|
126
|
+
billingIdentity: AiBillingIdentitySchema.optional(),
|
|
127
|
+
pricingContext: AiPricingContextSchema,
|
|
128
|
+
priceSource: AiPriceSourceSchema,
|
|
129
|
+
reason: z.enum([
|
|
130
|
+
"missingBillingIdentity",
|
|
131
|
+
"missingCatalogEntry",
|
|
132
|
+
"missingUsageMeter",
|
|
133
|
+
"unsupportedPricingDimension",
|
|
134
|
+
"invalidUsageForFormula",
|
|
135
|
+
]),
|
|
136
|
+
missingMeters: z.array(AiCostComponentSchema.shape.meter).optional(),
|
|
137
|
+
ratedAt: IsoDateSchema,
|
|
138
|
+
}),
|
|
139
|
+
])
|
|
140
|
+
|
|
141
|
+
const AiModelCallUsageRecordSchema = z.object({
|
|
142
|
+
id: z.string(),
|
|
143
|
+
executionId: z.string(),
|
|
144
|
+
attempt: z.number().int().positive(),
|
|
145
|
+
callId: z.string(),
|
|
146
|
+
providerId: z.string(),
|
|
147
|
+
requestedModelId: z.string(),
|
|
148
|
+
responseModelId: z.string().optional(),
|
|
149
|
+
responseId: z.string(),
|
|
150
|
+
usage: AiUsageSummarySchema,
|
|
151
|
+
occurredAt: IsoDateSchema,
|
|
152
|
+
recordedAt: IsoDateSchema,
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
export const AiModelCallAccountingItemSchema = z.object({
|
|
156
|
+
usage: AiModelCallUsageRecordSchema,
|
|
157
|
+
attribution: z
|
|
158
|
+
.discriminatedUnion("kind", [
|
|
159
|
+
z.object({
|
|
160
|
+
kind: z.literal("agent"),
|
|
161
|
+
agentId: z.string(),
|
|
162
|
+
agentRunId: z.string(),
|
|
163
|
+
threadId: z.string(),
|
|
164
|
+
}),
|
|
165
|
+
z.object({
|
|
166
|
+
kind: z.literal("workflowAgent"),
|
|
167
|
+
agentId: z.string(),
|
|
168
|
+
nodeRunId: z.string(),
|
|
169
|
+
workflowId: z.string(),
|
|
170
|
+
workflowRunId: z.string(),
|
|
171
|
+
}),
|
|
172
|
+
])
|
|
173
|
+
.optional(),
|
|
174
|
+
cost: AiModelCallCostSchema.optional(),
|
|
175
|
+
valuationStatus: AiValuationStatusSchema,
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
export const AiModelCallAccountingListResponseSchema = z.object({
|
|
179
|
+
items: z.array(AiModelCallAccountingItemSchema),
|
|
180
|
+
hasMore: z.boolean(),
|
|
181
|
+
total: z.number().int().nonnegative(),
|
|
182
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from "zod"
|
|
2
|
+
|
|
3
|
+
const TokenCountSchema = z.number().int().nonnegative()
|
|
4
|
+
|
|
5
|
+
/** Provider-neutral run usage aggregated from the durable model-call ledger. */
|
|
6
|
+
export const AiUsageSummarySchema = z.object({
|
|
7
|
+
inputTokens: TokenCountSchema.optional(),
|
|
8
|
+
outputTokens: TokenCountSchema.optional(),
|
|
9
|
+
totalTokens: TokenCountSchema.optional(),
|
|
10
|
+
uncachedInputTokens: TokenCountSchema.optional(),
|
|
11
|
+
cacheReadInputTokens: TokenCountSchema.optional(),
|
|
12
|
+
cacheWriteInputTokens: TokenCountSchema.optional(),
|
|
13
|
+
textOutputTokens: TokenCountSchema.optional(),
|
|
14
|
+
reasoningOutputTokens: TokenCountSchema.optional(),
|
|
15
|
+
reportingStatus: z.enum(["complete", "partial", "unavailable"]),
|
|
16
|
+
})
|
package/src/schemas/common.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
+
import type { SixbErrorCode } from "@sixb/core"
|
|
2
|
+
import { SIXB_FAILURE_MAX_MESSAGE_BYTES } from "@sixb/core/internal/errors"
|
|
1
3
|
import { z } from "zod"
|
|
2
4
|
import { ignoreOverride, type JsonSchema7Type, type OverrideCallback } from "zod-to-json-schema"
|
|
3
5
|
|
|
4
6
|
export const ErrorResponseSchema = z.object({ error: z.string() })
|
|
5
7
|
|
|
8
|
+
export function codedErrorResponseSchema<
|
|
9
|
+
const TCodes extends readonly [SixbErrorCode, ...SixbErrorCode[]],
|
|
10
|
+
>(codes: TCodes) {
|
|
11
|
+
return ErrorResponseSchema.extend({
|
|
12
|
+
code: z.enum(codes).describe("Stable machine-readable failure code for programmatic handling."),
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
6
16
|
export const SuccessResponseSchema = z.object({ success: z.boolean() })
|
|
7
17
|
|
|
8
18
|
export type JsonValue =
|
|
@@ -27,6 +37,20 @@ export const JsonValueSchema: z.ZodType<JsonValue> = z.lazy(() =>
|
|
|
27
37
|
/** A JSON null with an explicit runtime and generated-client type. */
|
|
28
38
|
export const JsonNullSchema = JsonValueSchema.refine((value): value is null => value === null)
|
|
29
39
|
|
|
40
|
+
/** Creates a portable failure record constrained to one boundary's declared codes. */
|
|
41
|
+
export function sixbFailureSchema<
|
|
42
|
+
const TCodes extends readonly [SixbErrorCode, ...SixbErrorCode[]],
|
|
43
|
+
>(codes: TCodes) {
|
|
44
|
+
return z.object({
|
|
45
|
+
code: z.enum(codes),
|
|
46
|
+
message: z.string().max(SIXB_FAILURE_MAX_MESSAGE_BYTES),
|
|
47
|
+
retryable: z.boolean(),
|
|
48
|
+
at: z.string().datetime(),
|
|
49
|
+
details: JsonValueSchema.optional(),
|
|
50
|
+
truncated: z.literal(true).optional(),
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
30
54
|
const JsonValueOpenApiSchema = {
|
|
31
55
|
description: "Any JSON-compatible value.",
|
|
32
56
|
nullable: true,
|
|
@@ -1,9 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CONNECTOR_CONNECTION_RUN_FAILURE_CODES,
|
|
3
|
+
type ConnectorConnectionRunFailure,
|
|
4
|
+
} from "@sixb/core/storage"
|
|
1
5
|
import { z } from "zod"
|
|
6
|
+
import { ErrorResponseSchema, sixbFailureSchema } from "./common"
|
|
7
|
+
|
|
8
|
+
export const CONNECTOR_HTTP_ERROR_CODES = [
|
|
9
|
+
"internal.unexpected",
|
|
10
|
+
"connector.adapter_invalid",
|
|
11
|
+
"connector.authorization_invalid",
|
|
12
|
+
"connector.authorization_required",
|
|
13
|
+
"connector.configuration_invalid",
|
|
14
|
+
"connector.credentials_unavailable",
|
|
15
|
+
"connector.not_found",
|
|
16
|
+
"connector.operation_conflict",
|
|
17
|
+
"connector.operation_in_progress",
|
|
18
|
+
"connector.provider_failed",
|
|
19
|
+
"connector.provider_unavailable",
|
|
20
|
+
"connector.replacement_required",
|
|
21
|
+
"connector.revocation_pending",
|
|
22
|
+
] as const
|
|
23
|
+
export type ConnectorHttpErrorCode = (typeof CONNECTOR_HTTP_ERROR_CODES)[number]
|
|
24
|
+
|
|
25
|
+
export const ConnectorBadRequestResponseSchema = connectorRouteErrorResponseSchema([
|
|
26
|
+
"connector.authorization_invalid",
|
|
27
|
+
"connector.configuration_invalid",
|
|
28
|
+
])
|
|
29
|
+
export const ConnectorNotFoundResponseSchema = connectorRouteErrorResponseSchema([
|
|
30
|
+
"connector.not_found",
|
|
31
|
+
])
|
|
32
|
+
export const ConnectorConflictResponseSchema = connectorRouteErrorResponseSchema([
|
|
33
|
+
"connector.authorization_required",
|
|
34
|
+
"connector.operation_conflict",
|
|
35
|
+
"connector.operation_in_progress",
|
|
36
|
+
"connector.replacement_required",
|
|
37
|
+
"connector.revocation_pending",
|
|
38
|
+
])
|
|
39
|
+
export const ConnectorInternalErrorResponseSchema = connectorRouteErrorResponseSchema([
|
|
40
|
+
"internal.unexpected",
|
|
41
|
+
])
|
|
42
|
+
export const ConnectorBadGatewayResponseSchema = connectorRouteErrorResponseSchema([
|
|
43
|
+
"connector.adapter_invalid",
|
|
44
|
+
"connector.provider_failed",
|
|
45
|
+
])
|
|
46
|
+
export const ConnectorUnavailableResponseSchema = connectorRouteErrorResponseSchema([
|
|
47
|
+
"connector.credentials_unavailable",
|
|
48
|
+
"connector.provider_unavailable",
|
|
49
|
+
])
|
|
2
50
|
|
|
3
51
|
export const ConnectorParamsSchema = z.object({
|
|
4
52
|
connectorId: z.string().min(1),
|
|
5
53
|
})
|
|
6
54
|
|
|
55
|
+
export const ConnectorConnectionParamsSchema = ConnectorParamsSchema.extend({
|
|
56
|
+
connectionId: z.string().min(1),
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
export const ConnectorConnectionRunParamsSchema = ConnectorParamsSchema.extend({
|
|
60
|
+
runId: z.string().min(1),
|
|
61
|
+
})
|
|
62
|
+
|
|
7
63
|
export const ConnectorWebhookSchema = z.object({
|
|
8
64
|
id: z.string(),
|
|
9
65
|
method: z.literal("POST"),
|
|
@@ -16,6 +72,114 @@ export const ConnectorWebhookSchema = z.object({
|
|
|
16
72
|
export const ConnectorSchema = z.object({
|
|
17
73
|
id: z.string(),
|
|
18
74
|
type: z.string(),
|
|
75
|
+
connection: z.object({ authentication: z.literal("oauth2") }).nullable(),
|
|
19
76
|
syncIds: z.array(z.string()),
|
|
20
77
|
webhooks: z.array(ConnectorWebhookSchema),
|
|
21
78
|
})
|
|
79
|
+
|
|
80
|
+
export const ConnectorAccountSchema = z.object({
|
|
81
|
+
id: z.string(),
|
|
82
|
+
label: z.string(),
|
|
83
|
+
description: z.string().optional(),
|
|
84
|
+
avatarUrl: z.string().url().optional(),
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
export const ConnectorConnectionSchema = z.object({
|
|
88
|
+
id: z.string(),
|
|
89
|
+
connectorId: z.string(),
|
|
90
|
+
owner: z.object({ type: z.literal("project") }),
|
|
91
|
+
slot: z.string(),
|
|
92
|
+
account: ConnectorAccountSchema,
|
|
93
|
+
status: z.enum(["connected", "needs_reauthorization", "disconnected"]),
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
const ConnectorConnectionRunFailureSchema: z.ZodType<ConnectorConnectionRunFailure> =
|
|
97
|
+
sixbFailureSchema(CONNECTOR_CONNECTION_RUN_FAILURE_CODES)
|
|
98
|
+
|
|
99
|
+
const ConnectorConnectionRunBaseSchema = z.object({
|
|
100
|
+
id: z.string(),
|
|
101
|
+
connectorId: z.string(),
|
|
102
|
+
kind: z.enum(["connect", "reauthorize"]),
|
|
103
|
+
owner: z.object({ type: z.literal("project") }),
|
|
104
|
+
slot: z.string(),
|
|
105
|
+
createdAt: z.string().datetime(),
|
|
106
|
+
updatedAt: z.string().datetime(),
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
export const ConnectorConnectionRunSchema = z.union([
|
|
110
|
+
ConnectorConnectionRunBaseSchema.extend({
|
|
111
|
+
status: z.literal("waiting"),
|
|
112
|
+
waitingFor: z.literal("provider_authorization"),
|
|
113
|
+
expiresAt: z.string().datetime(),
|
|
114
|
+
}),
|
|
115
|
+
ConnectorConnectionRunBaseSchema.extend({
|
|
116
|
+
status: z.literal("running"),
|
|
117
|
+
}),
|
|
118
|
+
ConnectorConnectionRunBaseSchema.extend({
|
|
119
|
+
status: z.literal("waiting"),
|
|
120
|
+
waitingFor: z.literal("account_selection"),
|
|
121
|
+
accounts: z.array(ConnectorAccountSchema),
|
|
122
|
+
expiresAt: z.string().datetime(),
|
|
123
|
+
}),
|
|
124
|
+
ConnectorConnectionRunBaseSchema.extend({
|
|
125
|
+
status: z.literal("succeeded"),
|
|
126
|
+
connections: z.array(ConnectorConnectionSchema),
|
|
127
|
+
finishedAt: z.string().datetime(),
|
|
128
|
+
}),
|
|
129
|
+
ConnectorConnectionRunBaseSchema.extend({
|
|
130
|
+
status: z.literal("failed"),
|
|
131
|
+
error: ConnectorConnectionRunFailureSchema,
|
|
132
|
+
finishedAt: z.string().datetime(),
|
|
133
|
+
}),
|
|
134
|
+
ConnectorConnectionRunBaseSchema.extend({
|
|
135
|
+
status: z.enum(["cancelled", "expired"]),
|
|
136
|
+
finishedAt: z.string().datetime(),
|
|
137
|
+
}),
|
|
138
|
+
])
|
|
139
|
+
|
|
140
|
+
export const StartConnectorConnectionRunBodySchema = z.object({
|
|
141
|
+
slot: z.string().trim().min(1),
|
|
142
|
+
returnTo: z.string().url(),
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
export const AddConnectorConnectionBodySchema = z.object({
|
|
146
|
+
slot: z.string().trim().min(1),
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
export const StartConnectorReauthorizationBodySchema = z.object({
|
|
150
|
+
returnTo: z.string().url(),
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
export const StartConnectorConnectionRunResponseSchema = z.object({
|
|
154
|
+
runId: z.string(),
|
|
155
|
+
authorizationUrl: z.string().url(),
|
|
156
|
+
affectedConnections: z.array(ConnectorConnectionSchema),
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
export const SelectConnectorConnectionRunAccountBodySchema = z.object({
|
|
160
|
+
accountId: z.string().trim().min(1),
|
|
161
|
+
replace: z.boolean().optional(),
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
export const ConnectorOAuthCallbackQuerySchema = z
|
|
165
|
+
.object({
|
|
166
|
+
state: z.string().min(1),
|
|
167
|
+
code: z.string().min(1).optional(),
|
|
168
|
+
auth_code: z.string().min(1).optional(),
|
|
169
|
+
error: z.string().min(1).optional(),
|
|
170
|
+
})
|
|
171
|
+
.refine((query) => [query.code, query.auth_code, query.error].filter(Boolean).length === 1, {
|
|
172
|
+
message: "OAuth callback must contain exactly one of code, auth_code, or error.",
|
|
173
|
+
})
|
|
174
|
+
.transform(({ auth_code, ...query }) => ({ ...query, code: query.code ?? auth_code }))
|
|
175
|
+
|
|
176
|
+
function connectorRouteErrorResponseSchema<
|
|
177
|
+
const TCodes extends readonly [ConnectorHttpErrorCode, ...ConnectorHttpErrorCode[]],
|
|
178
|
+
>(codes: TCodes) {
|
|
179
|
+
return ErrorResponseSchema.extend({
|
|
180
|
+
code: z
|
|
181
|
+
.enum(codes)
|
|
182
|
+
.optional()
|
|
183
|
+
.describe("Stable machine-readable failure code for programmatic handling."),
|
|
184
|
+
})
|
|
185
|
+
}
|
package/src/schemas/pipelines.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PIPELINE_RUN_FAILURE_CODES,
|
|
3
|
+
type PipelineRunFailureCode,
|
|
4
|
+
type SixbFailure,
|
|
5
|
+
} from "@sixb/core/storage"
|
|
1
6
|
import { z } from "zod"
|
|
7
|
+
import { sixbFailureSchema } from "./common"
|
|
2
8
|
import { DatasetDefinitionSchema } from "./datasets"
|
|
3
9
|
|
|
10
|
+
const PipelineRunFailureSchema: z.ZodType<SixbFailure<PipelineRunFailureCode>> = sixbFailureSchema(
|
|
11
|
+
PIPELINE_RUN_FAILURE_CODES
|
|
12
|
+
)
|
|
13
|
+
|
|
4
14
|
export const PipelineParamsSchema = z.object({
|
|
5
15
|
pipelineId: z.string().min(1),
|
|
6
16
|
})
|
|
@@ -9,7 +19,14 @@ export const PipelineRunParamsSchema = z.object({
|
|
|
9
19
|
runId: z.string().min(1),
|
|
10
20
|
})
|
|
11
21
|
|
|
12
|
-
export const PipelineRunStatusSchema = z.enum([
|
|
22
|
+
export const PipelineRunStatusSchema = z.enum([
|
|
23
|
+
"queued",
|
|
24
|
+
"running",
|
|
25
|
+
"succeeded",
|
|
26
|
+
"failed",
|
|
27
|
+
"cancelled",
|
|
28
|
+
])
|
|
29
|
+
const PipelineStepRunStatusSchema = z.enum(["running", "succeeded", "failed", "cancelled"])
|
|
13
30
|
|
|
14
31
|
export const PipelineRunsQuerySchema = z.object({
|
|
15
32
|
pipelineId: z.string().optional(),
|
|
@@ -46,15 +63,11 @@ export const PipelineRunSchema = z.object({
|
|
|
46
63
|
projectId: z.string(),
|
|
47
64
|
pipelineId: z.string(),
|
|
48
65
|
status: PipelineRunStatusSchema,
|
|
49
|
-
|
|
66
|
+
queuedAt: z.string(),
|
|
67
|
+
startedAt: z.string().optional(),
|
|
50
68
|
finishedAt: z.string().optional(),
|
|
51
69
|
output: DatasetVersionRefSchema.optional(),
|
|
52
|
-
error:
|
|
53
|
-
.object({
|
|
54
|
-
name: z.string().optional(),
|
|
55
|
-
message: z.string(),
|
|
56
|
-
})
|
|
57
|
-
.optional(),
|
|
70
|
+
error: PipelineRunFailureSchema.optional(),
|
|
58
71
|
})
|
|
59
72
|
|
|
60
73
|
export const PipelineStepRunSchema = z.object({
|
|
@@ -65,18 +78,13 @@ export const PipelineStepRunSchema = z.object({
|
|
|
65
78
|
stepId: z.string(),
|
|
66
79
|
datasetId: z.string(),
|
|
67
80
|
mode: z.enum(["snapshot", "append"]),
|
|
68
|
-
status:
|
|
81
|
+
status: PipelineStepRunStatusSchema,
|
|
69
82
|
startedAt: z.string(),
|
|
70
83
|
finishedAt: z.string().optional(),
|
|
71
84
|
inputs: z.array(DatasetVersionRefSchema),
|
|
72
85
|
output: DatasetVersionRefSchema.optional(),
|
|
73
86
|
rowsWritten: z.number().optional(),
|
|
74
|
-
error:
|
|
75
|
-
.object({
|
|
76
|
-
name: z.string().optional(),
|
|
77
|
-
message: z.string(),
|
|
78
|
-
})
|
|
79
|
-
.optional(),
|
|
87
|
+
error: PipelineRunFailureSchema.optional(),
|
|
80
88
|
})
|
|
81
89
|
|
|
82
90
|
export const PipelineStepSchema = z.object({
|
|
@@ -1,7 +1,19 @@
|
|
|
1
|
+
import type { SixbFailure } from "@sixb/core"
|
|
2
|
+
import { PROJECTION_RUN_FAILURE_CODES, type ProjectionRunFailureCode } from "@sixb/core/storage"
|
|
1
3
|
import { z } from "zod"
|
|
4
|
+
import { sixbFailureSchema } from "./common"
|
|
5
|
+
|
|
6
|
+
const ProjectionRunFailureSchema: z.ZodType<SixbFailure<ProjectionRunFailureCode>> =
|
|
7
|
+
sixbFailureSchema(PROJECTION_RUN_FAILURE_CODES)
|
|
2
8
|
|
|
3
9
|
export const ProjectionKindSchema = z.enum(["object", "link", "telemetry"])
|
|
4
|
-
export const ProjectionRunStatusSchema = z.enum([
|
|
10
|
+
export const ProjectionRunStatusSchema = z.enum([
|
|
11
|
+
"queued",
|
|
12
|
+
"running",
|
|
13
|
+
"succeeded",
|
|
14
|
+
"failed",
|
|
15
|
+
"cancelled",
|
|
16
|
+
])
|
|
5
17
|
|
|
6
18
|
const ProjectionRunIdentityBaseSchema = z.object({
|
|
7
19
|
projectionId: z.string(),
|
|
@@ -18,15 +30,17 @@ const ProjectionRunIdentityBaseSchema = z.object({
|
|
|
18
30
|
const ProjectionRunBaseSchema = z.object({
|
|
19
31
|
id: z.string(),
|
|
20
32
|
projectId: z.string(),
|
|
33
|
+
executionId: z.string(),
|
|
21
34
|
status: ProjectionRunStatusSchema,
|
|
22
35
|
attempt: z.number(),
|
|
23
36
|
progress: z.object({
|
|
24
37
|
sourceRowsRead: z.number(),
|
|
25
38
|
sourceRowsSkipped: z.number(),
|
|
26
39
|
}),
|
|
27
|
-
|
|
40
|
+
queuedAt: z.string(),
|
|
41
|
+
startedAt: z.string().optional(),
|
|
28
42
|
finishedAt: z.string().optional(),
|
|
29
|
-
|
|
43
|
+
error: ProjectionRunFailureSchema.optional(),
|
|
30
44
|
})
|
|
31
45
|
|
|
32
46
|
const ObjectProjectionRunSchema = ProjectionRunBaseSchema.extend({
|
|
@@ -69,6 +83,11 @@ export const ForeignKeyDescriptorSchema = z.object({
|
|
|
69
83
|
targetObjectTypeId: z.string(),
|
|
70
84
|
})
|
|
71
85
|
|
|
86
|
+
export const SourceEditConflictResolutionSchema = z.union([
|
|
87
|
+
z.object({ strategy: z.literal("editsWin") }),
|
|
88
|
+
z.object({ strategy: z.literal("mostRecent"), sourceTimestamp: z.string() }),
|
|
89
|
+
])
|
|
90
|
+
|
|
72
91
|
export const ObjectProjectionSchema = z.object({
|
|
73
92
|
_tag: z.literal("ObjectProjectionDefinition"),
|
|
74
93
|
id: z.string(),
|
|
@@ -76,6 +95,7 @@ export const ObjectProjectionSchema = z.object({
|
|
|
76
95
|
datasetId: z.string(),
|
|
77
96
|
properties: z.record(z.string()),
|
|
78
97
|
links: z.record(ForeignKeyDescriptorSchema),
|
|
98
|
+
conflictResolution: SourceEditConflictResolutionSchema,
|
|
79
99
|
latestRun: ProjectionRunSchema.nullable(),
|
|
80
100
|
})
|
|
81
101
|
|
package/src/schemas/syncs.ts
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type SixbFailure,
|
|
3
|
+
SYNC_RUN_FAILURE_CODES,
|
|
4
|
+
type SyncRunFailureCode,
|
|
5
|
+
} from "@sixb/core/storage"
|
|
1
6
|
import { z } from "zod"
|
|
7
|
+
import { sixbFailureSchema } from "./common"
|
|
2
8
|
import { DatasetDefinitionSchema } from "./datasets"
|
|
3
9
|
|
|
10
|
+
const SyncRunFailureSchema: z.ZodType<SixbFailure<SyncRunFailureCode>> =
|
|
11
|
+
sixbFailureSchema(SYNC_RUN_FAILURE_CODES)
|
|
12
|
+
|
|
4
13
|
export const SyncParamsSchema = z.object({
|
|
5
14
|
syncId: z.string().min(1),
|
|
6
15
|
})
|
|
7
16
|
|
|
8
|
-
export const SyncRunStatusSchema = z.enum(["running", "succeeded", "failed", "cancelled"])
|
|
17
|
+
export const SyncRunStatusSchema = z.enum(["queued", "running", "succeeded", "failed", "cancelled"])
|
|
9
18
|
const SyncModeSchema = z.enum(["snapshot", "append", "merge"])
|
|
10
19
|
|
|
11
20
|
export const SyncRunsQuerySchema = z.object({
|
|
@@ -36,7 +45,8 @@ export const SyncRunSchema = z.object({
|
|
|
36
45
|
datasetId: z.string(),
|
|
37
46
|
mode: SyncModeSchema,
|
|
38
47
|
status: SyncRunStatusSchema,
|
|
39
|
-
|
|
48
|
+
queuedAt: z.string(),
|
|
49
|
+
startedAt: z.string().optional(),
|
|
40
50
|
finishedAt: z.string().optional(),
|
|
41
51
|
rowsRead: z.number().optional(),
|
|
42
52
|
output: z
|
|
@@ -47,12 +57,7 @@ export const SyncRunSchema = z.object({
|
|
|
47
57
|
.optional(),
|
|
48
58
|
expectedLatestVersionId: z.string().optional(),
|
|
49
59
|
commitMessage: z.string().optional(),
|
|
50
|
-
error:
|
|
51
|
-
.object({
|
|
52
|
-
name: z.string().optional(),
|
|
53
|
-
message: z.string(),
|
|
54
|
-
})
|
|
55
|
-
.optional(),
|
|
60
|
+
error: SyncRunFailureSchema.optional(),
|
|
56
61
|
})
|
|
57
62
|
|
|
58
63
|
export const SyncSchema = z.object({
|