@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,165 @@
|
|
|
1
|
+
import type { SharedSessionContext } from "@sixb/core/internal/shares"
|
|
2
|
+
import type { Elysia } from "elysia"
|
|
3
|
+
import { CSRF_TOKEN_RESPONSE_HEADER_NAME } from "../auth/csrf"
|
|
4
|
+
import {
|
|
5
|
+
type SharedAccessBoundary,
|
|
6
|
+
sharedAccessForbiddenResponse,
|
|
7
|
+
sharedAccessSecurityHeaders,
|
|
8
|
+
sharedAccessUnauthenticatedResponse,
|
|
9
|
+
sharedAccessUnavailableResponse,
|
|
10
|
+
} from "../auth/shared-access"
|
|
11
|
+
import { SIXB_CSRF_SECURITY_REQUIREMENT } from "../openapi/security"
|
|
12
|
+
import { OPENAPI_TAGS } from "../openapi/tags"
|
|
13
|
+
import { ErrorResponseSchema } from "../schemas/common"
|
|
14
|
+
import {
|
|
15
|
+
ExchangeSharedAccessBodySchema,
|
|
16
|
+
SharedAccessGrantParamsSchema,
|
|
17
|
+
SharedAccessSessionResponseSchema,
|
|
18
|
+
SharedAccessSignOutResponseSchema,
|
|
19
|
+
} from "../schemas/shared-access"
|
|
20
|
+
|
|
21
|
+
export function registerSharedAccessRoutes(app: Elysia, boundary: SharedAccessBoundary) {
|
|
22
|
+
return app
|
|
23
|
+
.post(
|
|
24
|
+
"/api/shared-access/:grantId/exchange",
|
|
25
|
+
async ({ body, params, request }) => {
|
|
26
|
+
try {
|
|
27
|
+
const resolved = await boundary.exchange(request, params.grantId, body.secret)
|
|
28
|
+
if (!resolved) return sharedAccessUnauthenticatedResponse()
|
|
29
|
+
return sharedSessionResponse(resolved.context, resolved.cookies)
|
|
30
|
+
} catch {
|
|
31
|
+
return sharedAccessUnavailableResponse()
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
params: SharedAccessGrantParamsSchema,
|
|
36
|
+
body: ExchangeSharedAccessBodySchema,
|
|
37
|
+
response: {
|
|
38
|
+
200: SharedAccessSessionResponseSchema,
|
|
39
|
+
401: ErrorResponseSchema,
|
|
40
|
+
503: ErrorResponseSchema,
|
|
41
|
+
},
|
|
42
|
+
error: sharedAccessRouteError,
|
|
43
|
+
detail: {
|
|
44
|
+
summary: "Exchange a shared link for a short-lived session",
|
|
45
|
+
tags: [OPENAPI_TAGS.sharedAccess.name],
|
|
46
|
+
operationId: "exchangeSharedAccess",
|
|
47
|
+
security: [],
|
|
48
|
+
},
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
.get(
|
|
52
|
+
"/api/shared-access/:grantId/session",
|
|
53
|
+
async ({ params, request }) => {
|
|
54
|
+
try {
|
|
55
|
+
const resolved = await boundary.resolveSession(request, params.grantId)
|
|
56
|
+
if (!resolved) {
|
|
57
|
+
return withSetCookies(
|
|
58
|
+
sharedAccessUnauthenticatedResponse(),
|
|
59
|
+
boundary.clearCookieHeaders(request, params.grantId)
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
return sharedSessionResponse(resolved.context, resolved.cookies)
|
|
63
|
+
} catch {
|
|
64
|
+
return sharedAccessUnavailableResponse()
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
params: SharedAccessGrantParamsSchema,
|
|
69
|
+
response: {
|
|
70
|
+
200: SharedAccessSessionResponseSchema,
|
|
71
|
+
401: ErrorResponseSchema,
|
|
72
|
+
503: ErrorResponseSchema,
|
|
73
|
+
},
|
|
74
|
+
error: sharedAccessRouteError,
|
|
75
|
+
detail: {
|
|
76
|
+
summary: "Get the current shared-access session",
|
|
77
|
+
tags: [OPENAPI_TAGS.sharedAccess.name],
|
|
78
|
+
operationId: "getSharedAccessSession",
|
|
79
|
+
security: [],
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
.post(
|
|
84
|
+
"/api/shared-access/:grantId/sign-out",
|
|
85
|
+
async ({ params, request }) => {
|
|
86
|
+
try {
|
|
87
|
+
const result = await boundary.signOut(request, params.grantId)
|
|
88
|
+
if (result.kind === "csrf") return sharedAccessForbiddenResponse()
|
|
89
|
+
if (result.kind === "invalid") {
|
|
90
|
+
return withSetCookies(sharedAccessUnauthenticatedResponse(), result.setCookies)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const response = new Response(JSON.stringify({ signedOut: true }), {
|
|
94
|
+
status: 200,
|
|
95
|
+
headers: sharedAccessSecurityHeaders(),
|
|
96
|
+
})
|
|
97
|
+
return withSetCookies(response, result.setCookies)
|
|
98
|
+
} catch {
|
|
99
|
+
return sharedAccessUnavailableResponse()
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
params: SharedAccessGrantParamsSchema,
|
|
104
|
+
response: {
|
|
105
|
+
200: SharedAccessSignOutResponseSchema,
|
|
106
|
+
401: ErrorResponseSchema,
|
|
107
|
+
403: ErrorResponseSchema,
|
|
108
|
+
503: ErrorResponseSchema,
|
|
109
|
+
},
|
|
110
|
+
error: sharedAccessRouteError,
|
|
111
|
+
detail: {
|
|
112
|
+
summary: "Sign out a shared-access session",
|
|
113
|
+
tags: [OPENAPI_TAGS.sharedAccess.name],
|
|
114
|
+
operationId: "signOutSharedAccess",
|
|
115
|
+
security: SIXB_CSRF_SECURITY_REQUIREMENT,
|
|
116
|
+
},
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function sharedSessionResponse(
|
|
122
|
+
context: SharedSessionContext,
|
|
123
|
+
cookies: { readonly setCookies: readonly string[]; readonly csrfToken: string }
|
|
124
|
+
): Response {
|
|
125
|
+
const headers = sharedAccessSecurityHeaders()
|
|
126
|
+
headers.set(CSRF_TOKEN_RESPONSE_HEADER_NAME, cookies.csrfToken)
|
|
127
|
+
for (const cookie of cookies.setCookies) headers.append("set-cookie", cookie)
|
|
128
|
+
return new Response(
|
|
129
|
+
JSON.stringify({
|
|
130
|
+
grantId: context.grantId,
|
|
131
|
+
destinationPath: context.destinationPath,
|
|
132
|
+
expiresAt: context.expiresAt.toISOString(),
|
|
133
|
+
absoluteExpiresAt: context.absoluteExpiresAt.toISOString(),
|
|
134
|
+
csrfToken: cookies.csrfToken,
|
|
135
|
+
}),
|
|
136
|
+
{ status: 200, headers }
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function withSetCookies(response: Response, setCookies: readonly string[]): Response {
|
|
141
|
+
for (const cookie of setCookies) response.headers.append("set-cookie", cookie)
|
|
142
|
+
return response
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function sharedAccessRouteError(context: {
|
|
146
|
+
readonly code: unknown
|
|
147
|
+
readonly error: unknown
|
|
148
|
+
}): Response {
|
|
149
|
+
if (context.code === "PARSE" || isRequestValidationError(context)) {
|
|
150
|
+
return sharedAccessUnauthenticatedResponse()
|
|
151
|
+
}
|
|
152
|
+
return sharedAccessUnavailableResponse()
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function isRequestValidationError(context: {
|
|
156
|
+
readonly code: unknown
|
|
157
|
+
readonly error: unknown
|
|
158
|
+
}): boolean {
|
|
159
|
+
if (context.code !== "VALIDATION" || !isRecord(context.error)) return false
|
|
160
|
+
return ["body", "params", "query", "headers", "cookie"].includes(String(context.error.type))
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
164
|
+
return typeof value === "object" && value !== null
|
|
165
|
+
}
|
package/src/routes/workflows.ts
CHANGED
|
@@ -139,7 +139,6 @@ function serializePrincipal(principal: Principal) {
|
|
|
139
139
|
|
|
140
140
|
function serializeWorkflowAgentExecutionSummary(execution: WorkflowAgentNodeRunView) {
|
|
141
141
|
return {
|
|
142
|
-
agentId: execution.agentId,
|
|
143
142
|
status: execution.status,
|
|
144
143
|
attempt: execution.attempt,
|
|
145
144
|
modelId: execution.modelId,
|
|
@@ -205,7 +204,7 @@ function toWorkflowCancellationFailure(input: {
|
|
|
205
204
|
function toAgentCancellationFailure(input: {
|
|
206
205
|
readonly message: string
|
|
207
206
|
readonly at: Date
|
|
208
|
-
readonly
|
|
207
|
+
readonly agentStepId: string
|
|
209
208
|
readonly workflowId: string
|
|
210
209
|
readonly runId: string
|
|
211
210
|
readonly nodeRunId: string
|
|
@@ -213,7 +212,7 @@ function toAgentCancellationFailure(input: {
|
|
|
213
212
|
return toSixbFailure(
|
|
214
213
|
createSixbError("runtime.cancelled", input.message, {
|
|
215
214
|
details: {
|
|
216
|
-
|
|
215
|
+
agentStepId: input.agentStepId,
|
|
217
216
|
workflowId: input.workflowId,
|
|
218
217
|
workflowRunId: input.runId,
|
|
219
218
|
nodeRunId: input.nodeRunId,
|
|
@@ -385,7 +384,6 @@ function serializeWorkflow(
|
|
|
385
384
|
type: "agent" as const,
|
|
386
385
|
id: node.id,
|
|
387
386
|
key: node.key,
|
|
388
|
-
agentId: node.agentStep.agent.id,
|
|
389
387
|
input: node.agentStep.input,
|
|
390
388
|
output: node.agentStep.output,
|
|
391
389
|
}
|
|
@@ -1132,7 +1130,7 @@ export function registerWorkflowRoutes(app: Elysia, host: SixbHostView) {
|
|
|
1132
1130
|
error: toAgentCancellationFailure({
|
|
1133
1131
|
message: cancellationMessage,
|
|
1134
1132
|
at: cancelledAt,
|
|
1135
|
-
|
|
1133
|
+
agentStepId: active.nodeId,
|
|
1136
1134
|
workflowId: run.workflowId,
|
|
1137
1135
|
runId: run.id,
|
|
1138
1136
|
nodeRunId: active.id,
|
package/src/routes/ws/agents.ts
CHANGED
|
@@ -82,7 +82,7 @@ export async function canAccessAgentRunStream(
|
|
|
82
82
|
sixb: Sixb<readonly OntologySource[]>,
|
|
83
83
|
runId: string
|
|
84
84
|
): Promise<{ ok: true } | { ok: false; message: string }> {
|
|
85
|
-
const run = await sixb.
|
|
85
|
+
const run = await sixb.agent.runs.getById(runId)
|
|
86
86
|
if (!run) {
|
|
87
87
|
return { ok: false, message: "Agent run not found." }
|
|
88
88
|
}
|
|
@@ -93,8 +93,8 @@ export async function canAccessAgentThreadActivity(
|
|
|
93
93
|
sixb: Sixb<readonly OntologySource[]>,
|
|
94
94
|
event: AgentRunActivityEvent
|
|
95
95
|
): Promise<boolean> {
|
|
96
|
-
const
|
|
97
|
-
return
|
|
96
|
+
const run = await sixb.agent.runs.getById(event.runId)
|
|
97
|
+
return run?.projectId === event.projectId && run.threadId === event.threadId
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
export function registerAgentStreamRoutes(app: Elysia, server: SixbServer) {
|
|
@@ -318,7 +318,7 @@ async function sendVisibleActivityRecords(
|
|
|
318
318
|
events.map((event) => canAccessAgentThreadActivity(sixb, event))
|
|
319
319
|
)
|
|
320
320
|
for (const [index, event] of events.entries()) {
|
|
321
|
-
if (visible[index]) safeSend(ws, { type: "activity", event })
|
|
321
|
+
if (visible[index]) safeSend(ws, { type: "activity", event: serializeStreamPayload(event) })
|
|
322
322
|
}
|
|
323
323
|
}
|
|
324
324
|
|
|
@@ -401,7 +401,7 @@ async function sendRunSnapshot(
|
|
|
401
401
|
runId: string
|
|
402
402
|
): Promise<boolean> {
|
|
403
403
|
try {
|
|
404
|
-
const run = await sixb.
|
|
404
|
+
const run = await sixb.agent.runs.getById(runId)
|
|
405
405
|
if (!run) {
|
|
406
406
|
safeSend(ws, { type: "error", message: "Agent run not found." })
|
|
407
407
|
return false
|
|
@@ -422,10 +422,21 @@ function sendRecords(
|
|
|
422
422
|
records: readonly BrokerRecord[]
|
|
423
423
|
): void {
|
|
424
424
|
for (const record of records) {
|
|
425
|
-
safeSend(ws, {
|
|
425
|
+
safeSend(ws, {
|
|
426
|
+
type: "record",
|
|
427
|
+
record: { ...record, payload: serializeStreamPayload(record.payload) },
|
|
428
|
+
})
|
|
426
429
|
}
|
|
427
430
|
}
|
|
428
431
|
|
|
432
|
+
/** Stored records may predate the public contract; do not re-expose their retired selector. */
|
|
433
|
+
function serializeStreamPayload(payload: unknown): unknown {
|
|
434
|
+
if (payload === null || typeof payload !== "object" || Array.isArray(payload)) return payload
|
|
435
|
+
if (!("agentId" in payload)) return payload
|
|
436
|
+
const { agentId: _agentId, ...event } = payload
|
|
437
|
+
return event
|
|
438
|
+
}
|
|
439
|
+
|
|
429
440
|
function errorMessage(error: unknown): string {
|
|
430
441
|
return error instanceof Error ? error.message : String(error)
|
|
431
442
|
}
|
package/src/schemas/agents.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MAX_AGENT_CONTEXT_ENTRIES } from "@sixb/core"
|
|
2
2
|
import {
|
|
3
3
|
AGENT_RUN_DIAGNOSTIC_CODES,
|
|
4
4
|
AGENT_RUN_FAILURE_CODES,
|
|
@@ -11,14 +11,11 @@ import { AiCostSummarySchema } from "./ai-accounting"
|
|
|
11
11
|
import { AiUsageSummarySchema } from "./ai-usage"
|
|
12
12
|
import { JsonValueSchema, sixbFailureSchema } from "./common"
|
|
13
13
|
import { FileRefSchema } from "./files"
|
|
14
|
+
import { LanguageModelRefSchema, ModelReasoningSchema } from "./models"
|
|
14
15
|
|
|
15
16
|
export const AgentRunFailureSchema: z.ZodType<SixbFailure<AgentRunFailureCode>> =
|
|
16
17
|
sixbFailureSchema(AGENT_RUN_FAILURE_CODES)
|
|
17
18
|
|
|
18
|
-
export const AgentIdParamsSchema = z.object({
|
|
19
|
-
agentId: z.string().min(1),
|
|
20
|
-
})
|
|
21
|
-
|
|
22
19
|
export const AgentThreadParamsSchema = z.object({
|
|
23
20
|
threadId: z.string().min(1),
|
|
24
21
|
})
|
|
@@ -73,53 +70,32 @@ export const AgentContextPartSchema = AgentContextEntryInputSchema.extend({
|
|
|
73
70
|
type: z.literal("context"),
|
|
74
71
|
})
|
|
75
72
|
|
|
76
|
-
export const
|
|
77
|
-
stopWhen: z
|
|
78
|
-
.object({
|
|
79
|
-
maxSteps: z.number().int().positive().optional(),
|
|
80
|
-
})
|
|
81
|
-
.optional(),
|
|
82
|
-
context: z
|
|
83
|
-
.object({
|
|
84
|
-
windowTokens: z.number().int().positive().optional(),
|
|
85
|
-
reserveTokens: z.number().int().positive().optional(),
|
|
86
|
-
keepRecentTokens: z.number().int().positive().optional(),
|
|
87
|
-
})
|
|
88
|
-
.optional(),
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
export const AgentReasoningLevelSchema = z.enum(AGENT_REASONING_LEVELS)
|
|
92
|
-
|
|
93
|
-
export const AgentCatalogItemSchema = z.object({
|
|
94
|
-
id: z.string(),
|
|
73
|
+
export const AgentDescriptorSchema = z.object({
|
|
95
74
|
name: z.string(),
|
|
96
|
-
|
|
97
|
-
modelId: z.string().optional(),
|
|
98
|
-
reasoning: AgentReasoningLevelSchema.optional(),
|
|
99
|
-
groupIds: z.array(z.string()),
|
|
100
|
-
loop: AgentLoopConfigSchema.optional(),
|
|
75
|
+
model: LanguageModelRefSchema,
|
|
101
76
|
})
|
|
102
77
|
|
|
103
78
|
export const AgentThreadStatusSchema = z.enum(["active", "archived"])
|
|
104
79
|
|
|
105
|
-
export const AgentThreadListQuerySchema = z
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
80
|
+
export const AgentThreadListQuerySchema = z
|
|
81
|
+
.object({
|
|
82
|
+
status: AgentThreadStatusSchema.optional(),
|
|
83
|
+
limit: z.string().optional(),
|
|
84
|
+
offset: z.string().optional(),
|
|
85
|
+
order: z.enum(["asc", "desc"]).optional(),
|
|
86
|
+
})
|
|
87
|
+
.strict()
|
|
88
|
+
|
|
89
|
+
export const CreateAgentThreadBodySchema = z
|
|
90
|
+
.object({
|
|
91
|
+
title: z.string().trim().min(1).optional(),
|
|
92
|
+
threadId: z.string().trim().min(1).optional(),
|
|
93
|
+
})
|
|
94
|
+
.strict()
|
|
118
95
|
|
|
119
96
|
export const AgentThreadSchema = z.object({
|
|
120
97
|
id: z.string(),
|
|
121
98
|
projectId: z.string(),
|
|
122
|
-
agentId: z.string(),
|
|
123
99
|
ownerPrincipal: AgentPrincipalSchema,
|
|
124
100
|
title: z.string().optional(),
|
|
125
101
|
status: AgentThreadStatusSchema,
|
|
@@ -164,6 +140,12 @@ const AgentFilePartSchema = z.object({
|
|
|
164
140
|
providerMetadata: JsonValueSchema.optional(),
|
|
165
141
|
})
|
|
166
142
|
|
|
143
|
+
const AgentProviderStatePartSchema = z.object({
|
|
144
|
+
type: z.literal("provider-state"),
|
|
145
|
+
providerId: z.string(),
|
|
146
|
+
data: JsonValueSchema,
|
|
147
|
+
})
|
|
148
|
+
|
|
167
149
|
const AgentToolCallBaseSchema = z.object({
|
|
168
150
|
type: z.literal("tool-call"),
|
|
169
151
|
toolCallId: z.string(),
|
|
@@ -189,6 +171,7 @@ export const AgentMessagePartSchema = z.union([
|
|
|
189
171
|
AgentReasoningPartSchema,
|
|
190
172
|
AgentStepStartPartSchema,
|
|
191
173
|
AgentFilePartSchema,
|
|
174
|
+
AgentProviderStatePartSchema,
|
|
192
175
|
AgentContextPartSchema,
|
|
193
176
|
AgentToolCallOutputSchema,
|
|
194
177
|
AgentToolCallErrorSchema,
|
|
@@ -240,12 +223,16 @@ export const AgentMessageListResponseSchema = z.object({
|
|
|
240
223
|
total: z.number(),
|
|
241
224
|
})
|
|
242
225
|
|
|
243
|
-
export const PostAgentMessageBodySchema = z
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
226
|
+
export const PostAgentMessageBodySchema = z
|
|
227
|
+
.object({
|
|
228
|
+
text: z.string().trim().min(1),
|
|
229
|
+
model: LanguageModelRefSchema.optional(),
|
|
230
|
+
reasoning: ModelReasoningSchema.optional(),
|
|
231
|
+
attachments: z.array(FileRefSchema).optional(),
|
|
232
|
+
context: z.array(AgentContextEntryInputSchema).max(MAX_AGENT_CONTEXT_ENTRIES).optional(),
|
|
233
|
+
messageId: z.string().trim().min(1).optional(),
|
|
234
|
+
})
|
|
235
|
+
.strict()
|
|
249
236
|
|
|
250
237
|
export const CancelAgentRunBodySchema = z.object({
|
|
251
238
|
runId: z.string().trim().min(1),
|
|
@@ -265,10 +252,11 @@ export const AgentRunSchema = z.object({
|
|
|
265
252
|
id: z.string(),
|
|
266
253
|
projectId: z.string(),
|
|
267
254
|
threadId: z.string(),
|
|
268
|
-
agentId: z.string(),
|
|
269
255
|
triggerMessageId: z.string(),
|
|
270
256
|
requestedBy: AgentAuthorizablePrincipalSchema.optional(),
|
|
271
257
|
status: AgentRunStatusSchema,
|
|
258
|
+
model: LanguageModelRefSchema.optional(),
|
|
259
|
+
reasoning: ModelReasoningSchema.optional(),
|
|
272
260
|
modelId: z.string().optional(),
|
|
273
261
|
finishReason: AgentRunFinishReasonSchema.optional(),
|
|
274
262
|
usage: AiUsageSummarySchema.optional(),
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { z } from "zod"
|
|
2
2
|
import { AiUsageSummarySchema } from "./ai-usage"
|
|
3
|
+
import { ModelReasoningSchema } from "./models"
|
|
3
4
|
|
|
4
5
|
const IntegerStringSchema = z.string().regex(/^\d+$/)
|
|
5
6
|
const IsoDateSchema = z.string().datetime({ offset: true })
|
|
7
|
+
const CurrencySchema = z.string().regex(/^[A-Z]{3}$/)
|
|
8
|
+
|
|
9
|
+
export const AiMoneySchema = z.object({
|
|
10
|
+
currency: CurrencySchema,
|
|
11
|
+
amountNanos: IntegerStringSchema,
|
|
12
|
+
})
|
|
6
13
|
|
|
7
14
|
export const AiAccountingBucketSchema = z.enum(["hour", "day", "week"])
|
|
8
15
|
export const AiValuationStatusSchema = z.enum(["rated", "unpriceable", "unvalued"])
|
|
@@ -25,11 +32,6 @@ export const AiModelCallAccountingListQuerySchema = AiAccountingRangeQuerySchema
|
|
|
25
32
|
offset: IntegerStringSchema.optional(),
|
|
26
33
|
})
|
|
27
34
|
|
|
28
|
-
export const AiMoneySchema = z.object({
|
|
29
|
-
currency: z.string().regex(/^[A-Z]{3}$/),
|
|
30
|
-
amountNanos: IntegerStringSchema,
|
|
31
|
-
})
|
|
32
|
-
|
|
33
35
|
export const AiCostSummarySchema = z.object({
|
|
34
36
|
amounts: z.array(AiMoneySchema),
|
|
35
37
|
ratedCallCount: z.number().int().nonnegative(),
|
|
@@ -60,9 +62,14 @@ export const AiAccountingOverviewResponseSchema = z.object({
|
|
|
60
62
|
})
|
|
61
63
|
),
|
|
62
64
|
agents: z.array(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
z.discriminatedUnion("kind", [
|
|
66
|
+
AiAccountingAggregateSchema.extend({ kind: z.literal("agent") }),
|
|
67
|
+
AiAccountingAggregateSchema.extend({
|
|
68
|
+
kind: z.literal("workflowAgent"),
|
|
69
|
+
workflowId: z.string(),
|
|
70
|
+
agentStepId: z.string(),
|
|
71
|
+
}),
|
|
72
|
+
])
|
|
66
73
|
),
|
|
67
74
|
workflows: z.array(
|
|
68
75
|
AiAccountingAggregateSchema.extend({
|
|
@@ -77,6 +84,7 @@ export const AiPricingContextSchema = z.object({
|
|
|
77
84
|
region: z.string().optional(),
|
|
78
85
|
inferenceGeo: z.string().optional(),
|
|
79
86
|
routedProviderId: z.string().optional(),
|
|
87
|
+
routedModelId: z.string().optional(),
|
|
80
88
|
deploymentId: z.string().optional(),
|
|
81
89
|
inferenceProfileId: z.string().optional(),
|
|
82
90
|
cacheWriteTtlSeconds: z.number().int().positive().optional(),
|
|
@@ -89,6 +97,8 @@ const AiCostComponentSchema = z.object({
|
|
|
89
97
|
"tokens.input.uncached",
|
|
90
98
|
"tokens.input.cacheRead",
|
|
91
99
|
"tokens.input.cacheWrite",
|
|
100
|
+
"tokens.input.cacheWrite5m",
|
|
101
|
+
"tokens.input.cacheWrite1h",
|
|
92
102
|
"tokens.output.total",
|
|
93
103
|
"tokens.output.text",
|
|
94
104
|
"tokens.output.reasoning",
|
|
@@ -107,13 +117,36 @@ const AiPriceSourceSchema = z.object({
|
|
|
107
117
|
sourceId: z.string(),
|
|
108
118
|
sourceEntryId: z.string(),
|
|
109
119
|
sourceVersion: z.string(),
|
|
110
|
-
sourceUrl: z.string().url(),
|
|
120
|
+
sourceUrl: z.string().url().optional(),
|
|
111
121
|
observedAt: IsoDateSchema,
|
|
112
122
|
})
|
|
113
123
|
|
|
124
|
+
const AiCostSourceSchema = z.enum(["estimate", "provider", "unknown"])
|
|
125
|
+
const AiUnpriceableReasonSchema = z.enum([
|
|
126
|
+
"missingBillingIdentity",
|
|
127
|
+
"missingRateCard",
|
|
128
|
+
"missingUsageMeter",
|
|
129
|
+
"unsupportedPricingDimension",
|
|
130
|
+
"invalidUsageForFormula",
|
|
131
|
+
])
|
|
132
|
+
const AiCostEstimateSchema = z.discriminatedUnion("status", [
|
|
133
|
+
z.object({
|
|
134
|
+
status: z.literal("rated"),
|
|
135
|
+
money: AiMoneySchema,
|
|
136
|
+
components: z.array(AiCostComponentSchema),
|
|
137
|
+
}),
|
|
138
|
+
z.object({
|
|
139
|
+
status: z.literal("unpriceable"),
|
|
140
|
+
reason: AiUnpriceableReasonSchema,
|
|
141
|
+
missingMeters: z.array(AiCostComponentSchema.shape.meter).optional(),
|
|
142
|
+
}),
|
|
143
|
+
])
|
|
144
|
+
|
|
114
145
|
const AiModelCallCostSchema = z.discriminatedUnion("status", [
|
|
115
146
|
z.object({
|
|
116
147
|
status: z.literal("rated"),
|
|
148
|
+
source: AiCostSourceSchema,
|
|
149
|
+
estimate: AiCostEstimateSchema.optional(),
|
|
117
150
|
billingIdentity: AiBillingIdentitySchema,
|
|
118
151
|
pricingContext: AiPricingContextSchema,
|
|
119
152
|
priceSource: AiPriceSourceSchema,
|
|
@@ -123,16 +156,12 @@ const AiModelCallCostSchema = z.discriminatedUnion("status", [
|
|
|
123
156
|
}),
|
|
124
157
|
z.object({
|
|
125
158
|
status: z.literal("unpriceable"),
|
|
159
|
+
source: AiCostSourceSchema,
|
|
160
|
+
estimate: AiCostEstimateSchema.optional(),
|
|
126
161
|
billingIdentity: AiBillingIdentitySchema.optional(),
|
|
127
162
|
pricingContext: AiPricingContextSchema,
|
|
128
|
-
priceSource: AiPriceSourceSchema,
|
|
129
|
-
reason:
|
|
130
|
-
"missingBillingIdentity",
|
|
131
|
-
"missingCatalogEntry",
|
|
132
|
-
"missingUsageMeter",
|
|
133
|
-
"unsupportedPricingDimension",
|
|
134
|
-
"invalidUsageForFormula",
|
|
135
|
-
]),
|
|
163
|
+
priceSource: AiPriceSourceSchema.optional(),
|
|
164
|
+
reason: AiUnpriceableReasonSchema,
|
|
136
165
|
missingMeters: z.array(AiCostComponentSchema.shape.meter).optional(),
|
|
137
166
|
ratedAt: IsoDateSchema,
|
|
138
167
|
}),
|
|
@@ -145,8 +174,16 @@ const AiModelCallUsageRecordSchema = z.object({
|
|
|
145
174
|
callId: z.string(),
|
|
146
175
|
providerId: z.string(),
|
|
147
176
|
requestedModelId: z.string(),
|
|
177
|
+
requestedReasoning: ModelReasoningSchema.optional(),
|
|
148
178
|
responseModelId: z.string().optional(),
|
|
149
179
|
responseId: z.string(),
|
|
180
|
+
providerIds: z
|
|
181
|
+
.object({
|
|
182
|
+
requestId: z.string().optional(),
|
|
183
|
+
responseId: z.string().optional(),
|
|
184
|
+
generationId: z.string().optional(),
|
|
185
|
+
})
|
|
186
|
+
.nullable(),
|
|
150
187
|
usage: AiUsageSummarySchema,
|
|
151
188
|
occurredAt: IsoDateSchema,
|
|
152
189
|
recordedAt: IsoDateSchema,
|
|
@@ -158,17 +195,21 @@ export const AiModelCallAccountingItemSchema = z.object({
|
|
|
158
195
|
.discriminatedUnion("kind", [
|
|
159
196
|
z.object({
|
|
160
197
|
kind: z.literal("agent"),
|
|
161
|
-
agentId: z.string(),
|
|
162
198
|
agentRunId: z.string(),
|
|
163
199
|
threadId: z.string(),
|
|
164
200
|
}),
|
|
165
201
|
z.object({
|
|
166
202
|
kind: z.literal("workflowAgent"),
|
|
167
|
-
|
|
203
|
+
agentStepId: z.string(),
|
|
168
204
|
nodeRunId: z.string(),
|
|
169
205
|
workflowId: z.string(),
|
|
170
206
|
workflowRunId: z.string(),
|
|
171
207
|
}),
|
|
208
|
+
z.object({
|
|
209
|
+
kind: z.literal("subagent"),
|
|
210
|
+
subagentRunId: z.string(),
|
|
211
|
+
parentRunId: z.string(),
|
|
212
|
+
}),
|
|
172
213
|
])
|
|
173
214
|
.optional(),
|
|
174
215
|
cost: AiModelCallCostSchema.optional(),
|
|
@@ -180,3 +221,31 @@ export const AiModelCallAccountingListResponseSchema = z.object({
|
|
|
180
221
|
hasMore: z.boolean(),
|
|
181
222
|
total: z.number().int().nonnegative(),
|
|
182
223
|
})
|
|
224
|
+
|
|
225
|
+
export const AiModelCallGroupsQuerySchema = AiModelCallAccountingListQuerySchema.omit({
|
|
226
|
+
executionId: true,
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
const AiModelCallExecutionSummarySchema = z.object({
|
|
230
|
+
executionId: z.string(),
|
|
231
|
+
attribution: AiModelCallAccountingItemSchema.shape.attribution,
|
|
232
|
+
modelCallCount: z.number().int().nonnegative(),
|
|
233
|
+
totalTokens: z.number().int().nonnegative().optional(),
|
|
234
|
+
costs: AiCostSummarySchema,
|
|
235
|
+
firstCallAt: IsoDateSchema,
|
|
236
|
+
lastCallAt: IsoDateSchema,
|
|
237
|
+
models: z.array(AiBillingIdentitySchema),
|
|
238
|
+
/** Present only when the caller can read the initiating conversation. */
|
|
239
|
+
label: z.string().optional(),
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
export const AiModelCallGroupsResponseSchema = z.object({
|
|
243
|
+
items: z.array(
|
|
244
|
+
AiModelCallExecutionSummarySchema.omit({ models: true }).extend({
|
|
245
|
+
executions: z.array(AiModelCallExecutionSummarySchema),
|
|
246
|
+
canOpenThread: z.boolean(),
|
|
247
|
+
})
|
|
248
|
+
),
|
|
249
|
+
total: z.number().int().nonnegative(),
|
|
250
|
+
hasMore: z.boolean(),
|
|
251
|
+
})
|