@dexto/server 1.6.16 → 1.6.18
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/events/a2a-sse-subscriber.cjs +9 -2
- package/dist/events/a2a-sse-subscriber.d.ts.map +1 -1
- package/dist/events/a2a-sse-subscriber.js +9 -2
- package/dist/events/usage-event-subscriber.cjs +263 -0
- package/dist/events/usage-event-subscriber.d.ts +35 -0
- package/dist/events/usage-event-subscriber.d.ts.map +1 -0
- package/dist/events/usage-event-subscriber.js +244 -0
- package/dist/events/usage-event-types.cjs +16 -0
- package/dist/events/usage-event-types.d.ts +33 -0
- package/dist/events/usage-event-types.d.ts.map +1 -0
- package/dist/events/usage-event-types.js +0 -0
- package/dist/hono/__tests__/test-fixtures.cjs +3 -2
- package/dist/hono/__tests__/test-fixtures.d.ts +6 -2
- package/dist/hono/__tests__/test-fixtures.d.ts.map +1 -1
- package/dist/hono/__tests__/test-fixtures.js +3 -2
- package/dist/hono/index.d.ts +245 -33
- package/dist/hono/index.d.ts.map +1 -1
- package/dist/hono/routes/a2a-tasks.d.ts +9 -9
- package/dist/hono/routes/approvals.cjs +94 -6
- package/dist/hono/routes/approvals.d.ts +22 -6
- package/dist/hono/routes/approvals.d.ts.map +1 -1
- package/dist/hono/routes/approvals.js +94 -6
- package/dist/hono/routes/messages.cjs +16 -5
- package/dist/hono/routes/messages.d.ts +6 -0
- package/dist/hono/routes/messages.d.ts.map +1 -1
- package/dist/hono/routes/messages.js +17 -6
- package/dist/hono/routes/search.d.ts +10 -0
- package/dist/hono/routes/search.d.ts.map +1 -1
- package/dist/hono/routes/sessions.cjs +251 -2
- package/dist/hono/routes/sessions.d.ts +198 -18
- package/dist/hono/routes/sessions.d.ts.map +1 -1
- package/dist/hono/routes/sessions.js +259 -3
- package/dist/hono/routes/system-prompt.d.ts +1 -1
- package/dist/hono/schemas/responses.cjs +48 -8
- package/dist/hono/schemas/responses.d.ts +489 -22
- package/dist/hono/schemas/responses.d.ts.map +1 -1
- package/dist/hono/schemas/responses.js +49 -9
- package/dist/index.cjs +4 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/package.json +9 -9
|
@@ -1,12 +1,44 @@
|
|
|
1
1
|
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
|
2
|
+
import {
|
|
3
|
+
DextoRuntimeError,
|
|
4
|
+
ErrorScope,
|
|
5
|
+
ErrorType,
|
|
6
|
+
zodToIssues
|
|
7
|
+
} from "@dexto/core";
|
|
2
8
|
import {
|
|
3
9
|
SessionMetadataSchema,
|
|
4
10
|
InternalMessageSchema,
|
|
5
|
-
|
|
11
|
+
ScopedUsageSummarySchema,
|
|
12
|
+
StandardErrorEnvelopeSchema,
|
|
13
|
+
UsageSummarySchema
|
|
6
14
|
} from "../schemas/responses.js";
|
|
15
|
+
import { handleHonoError } from "../middleware/error.js";
|
|
7
16
|
const CreateSessionSchema = z.object({
|
|
8
17
|
sessionId: z.string().optional().describe("A custom ID for the new session")
|
|
9
18
|
}).describe("Request body for creating a new session");
|
|
19
|
+
const MAX_SYSTEM_PROMPT_CONTRIBUTOR_CONTENT_CHARS = 12e4;
|
|
20
|
+
const DEFAULT_SYSTEM_PROMPT_CONTRIBUTOR_PRIORITY = 45;
|
|
21
|
+
const SessionPromptContributorInfoSchema = z.object({
|
|
22
|
+
id: z.string().describe("Contributor identifier"),
|
|
23
|
+
priority: z.number().describe("Contributor priority")
|
|
24
|
+
}).strict().describe("Session-scoped system prompt contributor metadata.");
|
|
25
|
+
const UpsertSessionPromptContributorSchema = z.object({
|
|
26
|
+
id: z.string().min(1).describe("Contributor identifier"),
|
|
27
|
+
priority: z.number().int().nonnegative().optional().default(DEFAULT_SYSTEM_PROMPT_CONTRIBUTOR_PRIORITY).describe("Optional priority override"),
|
|
28
|
+
enabled: z.boolean().default(true).describe("Set false to remove the contributor instead of adding or updating it"),
|
|
29
|
+
content: z.string().optional().describe("Static contributor content for this session (required when enabled)")
|
|
30
|
+
}).strict().superRefine((value, ctx) => {
|
|
31
|
+
if (value.enabled !== false && (!value.content || value.content.trim().length === 0)) {
|
|
32
|
+
ctx.addIssue({
|
|
33
|
+
code: z.ZodIssueCode.custom,
|
|
34
|
+
path: ["content"],
|
|
35
|
+
message: "Contributor content is required when enabled"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}).describe("Session-scoped system prompt contributor update payload.");
|
|
39
|
+
function sanitizeContributorId(value) {
|
|
40
|
+
return value.trim().replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80);
|
|
41
|
+
}
|
|
10
42
|
function mapSessionMetadata(sessionId, metadata, defaults) {
|
|
11
43
|
return {
|
|
12
44
|
id: sessionId,
|
|
@@ -14,12 +46,35 @@ function mapSessionMetadata(sessionId, metadata, defaults) {
|
|
|
14
46
|
lastActivity: metadata?.lastActivity ?? defaults?.lastActivity ?? null,
|
|
15
47
|
messageCount: metadata?.messageCount ?? defaults?.messageCount ?? 0,
|
|
16
48
|
title: metadata?.title ?? defaults?.title ?? null,
|
|
49
|
+
...metadata?.tokenUsage && { tokenUsage: metadata.tokenUsage },
|
|
50
|
+
...metadata?.estimatedCost !== void 0 && {
|
|
51
|
+
estimatedCost: metadata.estimatedCost
|
|
52
|
+
},
|
|
53
|
+
...metadata?.modelStats && { modelStats: metadata.modelStats },
|
|
54
|
+
...metadata?.usageTracking && { usageTracking: metadata.usageTracking },
|
|
17
55
|
workspaceId: metadata?.workspaceId ?? defaults?.workspaceId ?? null,
|
|
18
56
|
parentSessionId: metadata?.parentSessionId ?? defaults?.parentSessionId ?? null
|
|
19
57
|
};
|
|
20
58
|
}
|
|
21
59
|
function createSessionsRouter(getAgent) {
|
|
22
|
-
const app = new OpenAPIHono(
|
|
60
|
+
const app = new OpenAPIHono({
|
|
61
|
+
defaultHook: (result, ctx) => {
|
|
62
|
+
if (!result.success) {
|
|
63
|
+
const issues = zodToIssues(result.error);
|
|
64
|
+
return handleHonoError(
|
|
65
|
+
ctx,
|
|
66
|
+
new DextoRuntimeError(
|
|
67
|
+
"validation_failed",
|
|
68
|
+
"validation",
|
|
69
|
+
ErrorType.USER,
|
|
70
|
+
issues[0]?.message ?? "Validation failed",
|
|
71
|
+
{ issues }
|
|
72
|
+
)
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
app.onError((err, ctx) => handleHonoError(ctx, err));
|
|
23
78
|
const listRoute = createRoute({
|
|
24
79
|
method: "get",
|
|
25
80
|
path: "/sessions",
|
|
@@ -148,6 +203,86 @@ function createSessionsRouter(getAgent) {
|
|
|
148
203
|
}
|
|
149
204
|
}
|
|
150
205
|
});
|
|
206
|
+
const listSessionPromptContributorsRoute = createRoute({
|
|
207
|
+
method: "get",
|
|
208
|
+
path: "/sessions/{sessionId}/system-prompt/contributors",
|
|
209
|
+
summary: "List Session System Prompt Contributors",
|
|
210
|
+
description: "Lists static system prompt contributors that apply only to the specified session.",
|
|
211
|
+
tags: ["sessions", "config"],
|
|
212
|
+
request: { params: z.object({ sessionId: z.string().describe("Session identifier") }) },
|
|
213
|
+
responses: {
|
|
214
|
+
200: {
|
|
215
|
+
description: "Current session contributor list",
|
|
216
|
+
content: {
|
|
217
|
+
"application/json": {
|
|
218
|
+
schema: z.object({
|
|
219
|
+
contributors: z.array(SessionPromptContributorInfoSchema).describe("Registered session prompt contributors.")
|
|
220
|
+
}).strict()
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
404: {
|
|
225
|
+
description: "Session not found",
|
|
226
|
+
content: {
|
|
227
|
+
"application/json": {
|
|
228
|
+
schema: StandardErrorEnvelopeSchema
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
const upsertSessionPromptContributorRoute = createRoute({
|
|
235
|
+
method: "post",
|
|
236
|
+
path: "/sessions/{sessionId}/system-prompt/contributors",
|
|
237
|
+
summary: "Upsert Session System Prompt Contributor",
|
|
238
|
+
description: "Adds or updates a static system prompt contributor that applies only to the specified session. Set enabled=false to remove it.",
|
|
239
|
+
tags: ["sessions", "config"],
|
|
240
|
+
request: {
|
|
241
|
+
params: z.object({ sessionId: z.string().describe("Session identifier") }),
|
|
242
|
+
body: {
|
|
243
|
+
required: true,
|
|
244
|
+
content: {
|
|
245
|
+
"application/json": {
|
|
246
|
+
schema: UpsertSessionPromptContributorSchema
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
responses: {
|
|
252
|
+
200: {
|
|
253
|
+
description: "Session contributor upsert result",
|
|
254
|
+
content: {
|
|
255
|
+
"application/json": {
|
|
256
|
+
schema: z.object({
|
|
257
|
+
id: z.string().describe("Contributor identifier"),
|
|
258
|
+
enabled: z.boolean().describe("Whether the contributor remains enabled"),
|
|
259
|
+
priority: z.number().optional().describe("Contributor priority"),
|
|
260
|
+
replaced: z.boolean().optional().describe("Whether an existing contributor was replaced"),
|
|
261
|
+
removed: z.boolean().optional().describe("Whether the contributor was removed"),
|
|
262
|
+
contentLength: z.number().optional().describe("Stored content length in characters"),
|
|
263
|
+
truncated: z.boolean().optional().describe("Whether the submitted content was truncated")
|
|
264
|
+
}).strict()
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
400: {
|
|
269
|
+
description: "Invalid session contributor request",
|
|
270
|
+
content: {
|
|
271
|
+
"application/json": {
|
|
272
|
+
schema: StandardErrorEnvelopeSchema
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
404: {
|
|
277
|
+
description: "Session not found",
|
|
278
|
+
content: {
|
|
279
|
+
"application/json": {
|
|
280
|
+
schema: StandardErrorEnvelopeSchema
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
});
|
|
151
286
|
const deleteRoute = createRoute({
|
|
152
287
|
method: "delete",
|
|
153
288
|
path: "/sessions/{sessionId}",
|
|
@@ -226,6 +361,15 @@ function createSessionsRouter(getAgent) {
|
|
|
226
361
|
session: SessionMetadataSchema.extend({
|
|
227
362
|
isBusy: z.boolean().describe(
|
|
228
363
|
"Whether the session is currently processing a message"
|
|
364
|
+
),
|
|
365
|
+
usageSummary: UsageSummarySchema.describe(
|
|
366
|
+
"Exact usage summary derived from assistant message history"
|
|
367
|
+
),
|
|
368
|
+
activeUsageScopeId: z.string().nullable().describe(
|
|
369
|
+
"Current runtime usage scope identifier, if configured"
|
|
370
|
+
),
|
|
371
|
+
activeUsageScope: ScopedUsageSummarySchema.nullable().describe(
|
|
372
|
+
"Usage summary for the current runtime scope, if configured"
|
|
229
373
|
)
|
|
230
374
|
}).describe("Session metadata with processing status")
|
|
231
375
|
}).strict()
|
|
@@ -244,6 +388,29 @@ function createSessionsRouter(getAgent) {
|
|
|
244
388
|
}
|
|
245
389
|
}
|
|
246
390
|
});
|
|
391
|
+
const clearContextRoute = createRoute({
|
|
392
|
+
method: "post",
|
|
393
|
+
path: "/sessions/{sessionId}/clear-context",
|
|
394
|
+
summary: "Clear Session Context",
|
|
395
|
+
description: "Clears the model context window for a session while preserving conversation history for review.",
|
|
396
|
+
tags: ["sessions"],
|
|
397
|
+
request: {
|
|
398
|
+
params: z.object({ sessionId: z.string().describe("Session identifier") })
|
|
399
|
+
},
|
|
400
|
+
responses: {
|
|
401
|
+
200: {
|
|
402
|
+
description: "Session context cleared successfully",
|
|
403
|
+
content: {
|
|
404
|
+
"application/json": {
|
|
405
|
+
schema: z.object({
|
|
406
|
+
status: z.literal("context cleared").describe("Context clear status"),
|
|
407
|
+
sessionId: z.string().describe("Session ID")
|
|
408
|
+
}).strict()
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
});
|
|
247
414
|
const patchRoute = createRoute({
|
|
248
415
|
method: "patch",
|
|
249
416
|
path: "/sessions/{sessionId}",
|
|
@@ -362,6 +529,81 @@ function createSessionsRouter(getAgent) {
|
|
|
362
529
|
history,
|
|
363
530
|
isBusy
|
|
364
531
|
});
|
|
532
|
+
}).openapi(listSessionPromptContributorsRoute, async (ctx) => {
|
|
533
|
+
const agent = await getAgent(ctx);
|
|
534
|
+
const { sessionId } = ctx.req.valid("param");
|
|
535
|
+
const contributors = await agent.getSessionSystemPromptContributors(sessionId);
|
|
536
|
+
return ctx.json(
|
|
537
|
+
{
|
|
538
|
+
contributors: contributors.map((contributor) => ({
|
|
539
|
+
id: contributor.id,
|
|
540
|
+
priority: contributor.priority
|
|
541
|
+
}))
|
|
542
|
+
},
|
|
543
|
+
200
|
|
544
|
+
);
|
|
545
|
+
}).openapi(upsertSessionPromptContributorRoute, async (ctx) => {
|
|
546
|
+
const agent = await getAgent(ctx);
|
|
547
|
+
const { sessionId } = ctx.req.valid("param");
|
|
548
|
+
const payload = ctx.req.valid("json");
|
|
549
|
+
const contributorId = sanitizeContributorId(payload.id);
|
|
550
|
+
if (contributorId.length === 0) {
|
|
551
|
+
throw new DextoRuntimeError(
|
|
552
|
+
"session_systemprompt_contributor_config_invalid",
|
|
553
|
+
ErrorScope.SYSTEM_PROMPT,
|
|
554
|
+
ErrorType.USER,
|
|
555
|
+
"A valid contributor id is required",
|
|
556
|
+
{
|
|
557
|
+
id: payload.id,
|
|
558
|
+
sessionId
|
|
559
|
+
}
|
|
560
|
+
);
|
|
561
|
+
}
|
|
562
|
+
const rawContent = payload.content ?? "";
|
|
563
|
+
const content = rawContent.slice(0, MAX_SYSTEM_PROMPT_CONTRIBUTOR_CONTENT_CHARS);
|
|
564
|
+
if (!payload.enabled) {
|
|
565
|
+
const removed = await agent.removeSessionSystemPromptContributor(
|
|
566
|
+
sessionId,
|
|
567
|
+
contributorId
|
|
568
|
+
);
|
|
569
|
+
return ctx.json(
|
|
570
|
+
{
|
|
571
|
+
id: contributorId,
|
|
572
|
+
enabled: false,
|
|
573
|
+
removed
|
|
574
|
+
},
|
|
575
|
+
200
|
|
576
|
+
);
|
|
577
|
+
}
|
|
578
|
+
if (content.trim().length === 0) {
|
|
579
|
+
throw new DextoRuntimeError(
|
|
580
|
+
"session_systemprompt_contributor_config_invalid",
|
|
581
|
+
ErrorScope.SYSTEM_PROMPT,
|
|
582
|
+
ErrorType.USER,
|
|
583
|
+
"Contributor content is required when enabled",
|
|
584
|
+
{
|
|
585
|
+
id: payload.id,
|
|
586
|
+
sessionId
|
|
587
|
+
}
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
const priority = payload.priority;
|
|
591
|
+
const result = await agent.upsertSessionSystemPromptContributor(sessionId, {
|
|
592
|
+
id: contributorId,
|
|
593
|
+
priority,
|
|
594
|
+
content
|
|
595
|
+
});
|
|
596
|
+
return ctx.json(
|
|
597
|
+
{
|
|
598
|
+
id: contributorId,
|
|
599
|
+
enabled: true,
|
|
600
|
+
priority,
|
|
601
|
+
replaced: result.replaced,
|
|
602
|
+
contentLength: content.length,
|
|
603
|
+
truncated: rawContent.length > content.length
|
|
604
|
+
},
|
|
605
|
+
200
|
|
606
|
+
);
|
|
365
607
|
}).openapi(deleteRoute, async (ctx) => {
|
|
366
608
|
const agent = await getAgent(ctx);
|
|
367
609
|
const { sessionId } = ctx.req.param();
|
|
@@ -405,15 +647,29 @@ function createSessionsRouter(getAgent) {
|
|
|
405
647
|
}
|
|
406
648
|
const metadata = await agent.getSessionMetadata(sessionId);
|
|
407
649
|
const isBusy = await agent.isSessionBusy(sessionId);
|
|
650
|
+
const usageSummary = await agent.getSessionUsageSummary(sessionId);
|
|
651
|
+
const activeUsageScopeId = agent.getEffectiveConfig().usageScopeId ?? null;
|
|
652
|
+
const activeUsageScope = activeUsageScopeId ? {
|
|
653
|
+
scopeId: activeUsageScopeId,
|
|
654
|
+
...await agent.getSessionUsageSummary(sessionId, activeUsageScopeId)
|
|
655
|
+
} : null;
|
|
408
656
|
return ctx.json(
|
|
409
657
|
{
|
|
410
658
|
session: {
|
|
411
659
|
...mapSessionMetadata(sessionId, metadata),
|
|
412
|
-
isBusy
|
|
660
|
+
isBusy,
|
|
661
|
+
usageSummary,
|
|
662
|
+
activeUsageScopeId,
|
|
663
|
+
activeUsageScope
|
|
413
664
|
}
|
|
414
665
|
},
|
|
415
666
|
200
|
|
416
667
|
);
|
|
668
|
+
}).openapi(clearContextRoute, async (ctx) => {
|
|
669
|
+
const agent = await getAgent(ctx);
|
|
670
|
+
const { sessionId } = ctx.req.valid("param");
|
|
671
|
+
await agent.clearContext(sessionId);
|
|
672
|
+
return ctx.json({ status: "context cleared", sessionId });
|
|
417
673
|
}).openapi(patchRoute, async (ctx) => {
|
|
418
674
|
const agent = await getAgent(ctx);
|
|
419
675
|
const { sessionId } = ctx.req.valid("param");
|
|
@@ -42,9 +42,9 @@ export declare function createSystemPromptRouter(getAgent: GetAgentFn): OpenAPIH
|
|
|
42
42
|
output: {
|
|
43
43
|
id: string;
|
|
44
44
|
enabled: boolean;
|
|
45
|
-
removed?: boolean | undefined;
|
|
46
45
|
priority?: number | undefined;
|
|
47
46
|
replaced?: boolean | undefined;
|
|
47
|
+
removed?: boolean | undefined;
|
|
48
48
|
contentLength?: number | undefined;
|
|
49
49
|
truncated?: boolean | undefined;
|
|
50
50
|
};
|
|
@@ -39,6 +39,7 @@ __export(responses_exports, {
|
|
|
39
39
|
ModelStatisticsSchema: () => ModelStatisticsSchema,
|
|
40
40
|
OkResponseSchema: () => OkResponseSchema,
|
|
41
41
|
PermissionsConfigSchema: () => import_core6.PermissionsConfigSchema,
|
|
42
|
+
PricingStatusSchema: () => PricingStatusSchema,
|
|
42
43
|
PromptArgumentSchema: () => PromptArgumentSchema,
|
|
43
44
|
PromptDefinitionSchema: () => PromptDefinitionSchema,
|
|
44
45
|
PromptInfoSchema: () => PromptInfoSchema,
|
|
@@ -48,11 +49,13 @@ __export(responses_exports, {
|
|
|
48
49
|
ResourceSchema: () => ResourceSchema,
|
|
49
50
|
ScheduleSchema: () => ScheduleSchema,
|
|
50
51
|
ScheduleTaskSchema: () => ScheduleTaskSchema,
|
|
52
|
+
ScopedUsageSummarySchema: () => ScopedUsageSummarySchema,
|
|
51
53
|
SearchResultSchema: () => SearchResultSchema,
|
|
52
54
|
SessionMetadataSchema: () => SessionMetadataSchema,
|
|
53
55
|
SessionSearchResponseSchema: () => SessionSearchResponseSchema,
|
|
54
56
|
SessionSearchResultSchema: () => SessionSearchResultSchema,
|
|
55
57
|
SessionTokenUsageSchema: () => SessionTokenUsageSchema,
|
|
58
|
+
SessionUsageTrackingSchema: () => SessionUsageTrackingSchema,
|
|
56
59
|
SseServerConfigSchema: () => import_core5.SseServerConfigSchema,
|
|
57
60
|
StandardErrorEnvelopeSchema: () => StandardErrorEnvelopeSchema,
|
|
58
61
|
StatusResponseSchema: () => StatusResponseSchema,
|
|
@@ -62,6 +65,7 @@ __export(responses_exports, {
|
|
|
62
65
|
ToolCallSchema: () => ToolCallSchema,
|
|
63
66
|
ToolSchema: () => ToolSchema,
|
|
64
67
|
UIResourcePartSchema: () => UIResourcePartSchema,
|
|
68
|
+
UsageSummarySchema: () => UsageSummarySchema,
|
|
65
69
|
WebhookSchema: () => WebhookSchema,
|
|
66
70
|
WorkspaceSchema: () => WorkspaceSchema
|
|
67
71
|
});
|
|
@@ -121,8 +125,11 @@ const TokenUsageSchema = import_zod.z.object({
|
|
|
121
125
|
inputTokens: import_zod.z.number().int().nonnegative().optional().describe("Number of input tokens"),
|
|
122
126
|
outputTokens: import_zod.z.number().int().nonnegative().optional().describe("Number of output tokens"),
|
|
123
127
|
reasoningTokens: import_zod.z.number().int().nonnegative().optional().describe("Number of reasoning tokens"),
|
|
128
|
+
cacheReadTokens: import_zod.z.number().int().nonnegative().optional().describe("Number of cache read tokens"),
|
|
129
|
+
cacheWriteTokens: import_zod.z.number().int().nonnegative().optional().describe("Number of cache write tokens"),
|
|
124
130
|
totalTokens: import_zod.z.number().int().nonnegative().optional().describe("Total tokens used")
|
|
125
131
|
}).strict().describe("Token usage accounting");
|
|
132
|
+
const PricingStatusSchema = import_zod.z.enum(import_core.LLM_PRICING_STATUSES).describe("Whether pricing was resolved for this response");
|
|
126
133
|
const InternalMessageSchema = import_zod.z.object({
|
|
127
134
|
id: import_zod.z.string().uuid().optional().describe("Unique message identifier (UUID)"),
|
|
128
135
|
role: import_zod.z.enum(["system", "user", "assistant", "tool"]).describe("Role of the message sender"),
|
|
@@ -130,6 +137,11 @@ const InternalMessageSchema = import_zod.z.object({
|
|
|
130
137
|
content: import_zod.z.union([import_zod.z.string(), import_zod.z.null(), import_zod.z.array(ContentPartSchema)]).describe("Message content (string, null, or array of parts)"),
|
|
131
138
|
reasoning: import_zod.z.string().optional().describe("Optional model reasoning text"),
|
|
132
139
|
tokenUsage: TokenUsageSchema.optional().describe("Optional token usage accounting"),
|
|
140
|
+
estimatedCost: import_zod.z.number().nonnegative().optional().describe("Estimated cost in USD for this response"),
|
|
141
|
+
pricingStatus: PricingStatusSchema.optional().describe(
|
|
142
|
+
"Whether pricing was resolved for this response"
|
|
143
|
+
),
|
|
144
|
+
usageScopeId: import_zod.z.string().optional().describe("Optional usage scope identifier for runtime-scoped metering"),
|
|
133
145
|
model: import_zod.z.string().optional().describe("Model identifier for assistant messages"),
|
|
134
146
|
provider: import_zod.z.enum(import_core.LLM_PROVIDERS).optional().describe("Provider identifier for assistant messages"),
|
|
135
147
|
toolCalls: import_zod.z.array(ToolCallSchema).optional().describe("Tool calls made by the assistant"),
|
|
@@ -141,14 +153,12 @@ const LLMConfigResponseSchema = import_core.LLMConfigBaseSchema.omit({ apiKey: t
|
|
|
141
153
|
hasApiKey: import_zod.z.boolean().optional().describe("Whether an API key is configured")
|
|
142
154
|
}).describe("LLM configuration (apiKey omitted for security)");
|
|
143
155
|
const LLMConfigSchema = import_core.LLMConfigBaseSchema.describe("LLM configuration with API key");
|
|
144
|
-
const SessionTokenUsageSchema =
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
totalTokens: import_zod.z.number().int().nonnegative().describe("Total tokens used")
|
|
151
|
-
}).strict().describe("Session-level token usage (all fields required for cumulative totals)");
|
|
156
|
+
const SessionTokenUsageSchema = TokenUsageSchema.required().describe(
|
|
157
|
+
"Session-level token usage (all fields required for cumulative totals)"
|
|
158
|
+
);
|
|
159
|
+
const SessionUsageTrackingSchema = import_zod.z.object({
|
|
160
|
+
hasUntrackedChatGPTLoginUsage: import_zod.z.boolean().optional().describe("Whether this session includes known untracked ChatGPT Login usage")
|
|
161
|
+
}).strict().describe("Usage tracking caveats for a session");
|
|
152
162
|
const ModelStatisticsSchema = import_zod.z.object({
|
|
153
163
|
provider: import_zod.z.string().describe("LLM provider identifier"),
|
|
154
164
|
model: import_zod.z.string().describe("Model identifier"),
|
|
@@ -158,6 +168,29 @@ const ModelStatisticsSchema = import_zod.z.object({
|
|
|
158
168
|
firstUsedAt: import_zod.z.number().int().positive().describe("First use timestamp (Unix ms)"),
|
|
159
169
|
lastUsedAt: import_zod.z.number().int().positive().describe("Last use timestamp (Unix ms)")
|
|
160
170
|
}).strict().describe("Per-model statistics within a session");
|
|
171
|
+
const UsageSummarySchema = import_zod.z.object({
|
|
172
|
+
tokenUsage: SessionTokenUsageSchema.describe(
|
|
173
|
+
"Aggregate token usage for the selected scope"
|
|
174
|
+
),
|
|
175
|
+
estimatedCost: import_zod.z.number().nonnegative().describe("Total estimated cost in USD for the selected scope"),
|
|
176
|
+
hasUnpricedResponses: import_zod.z.boolean().describe(
|
|
177
|
+
"Whether any response in the selected scope has usage but no resolved pricing"
|
|
178
|
+
),
|
|
179
|
+
modelStats: import_zod.z.array(
|
|
180
|
+
import_zod.z.object({
|
|
181
|
+
provider: import_zod.z.string().describe("LLM provider identifier"),
|
|
182
|
+
model: import_zod.z.string().describe("Model identifier"),
|
|
183
|
+
messageCount: import_zod.z.number().int().nonnegative().describe("Number of responses using this model in the selected scope"),
|
|
184
|
+
tokenUsage: SessionTokenUsageSchema.describe(
|
|
185
|
+
"Token usage for this model in the selected scope"
|
|
186
|
+
),
|
|
187
|
+
estimatedCost: import_zod.z.number().nonnegative().describe("Estimated cost in USD for this model in the selected scope")
|
|
188
|
+
}).strict()
|
|
189
|
+
).optional().describe("Per-model usage statistics within the selected scope")
|
|
190
|
+
}).strict().describe("Usage summary for a session or session scope");
|
|
191
|
+
const ScopedUsageSummarySchema = UsageSummarySchema.extend({
|
|
192
|
+
scopeId: import_zod.z.string().describe("Usage scope identifier")
|
|
193
|
+
}).strict().describe("Usage summary for a specific scope within a session");
|
|
161
194
|
const SessionMetadataSchema = import_zod.z.object({
|
|
162
195
|
id: import_zod.z.string().describe("Unique session identifier"),
|
|
163
196
|
createdAt: import_zod.z.number().int().positive().nullable().describe("Creation timestamp (Unix ms, null if unavailable)"),
|
|
@@ -169,6 +202,9 @@ const SessionMetadataSchema = import_zod.z.object({
|
|
|
169
202
|
),
|
|
170
203
|
estimatedCost: import_zod.z.number().nonnegative().optional().describe("Total estimated cost in USD across all models"),
|
|
171
204
|
modelStats: import_zod.z.array(ModelStatisticsSchema).optional().describe("Per-model usage statistics (for multi-model sessions)"),
|
|
205
|
+
usageTracking: SessionUsageTrackingSchema.optional().describe(
|
|
206
|
+
"Known caveats or gaps in usage tracking for this session"
|
|
207
|
+
),
|
|
172
208
|
workspaceId: import_zod.z.string().optional().nullable().describe("Associated workspace ID, if any"),
|
|
173
209
|
parentSessionId: import_zod.z.string().optional().nullable().describe("Parent session ID if this session was forked, otherwise null")
|
|
174
210
|
}).strict().describe("Session metadata");
|
|
@@ -379,6 +415,7 @@ const DeleteResponseSchema = import_zod.z.object({
|
|
|
379
415
|
ModelStatisticsSchema,
|
|
380
416
|
OkResponseSchema,
|
|
381
417
|
PermissionsConfigSchema,
|
|
418
|
+
PricingStatusSchema,
|
|
382
419
|
PromptArgumentSchema,
|
|
383
420
|
PromptDefinitionSchema,
|
|
384
421
|
PromptInfoSchema,
|
|
@@ -388,11 +425,13 @@ const DeleteResponseSchema = import_zod.z.object({
|
|
|
388
425
|
ResourceSchema,
|
|
389
426
|
ScheduleSchema,
|
|
390
427
|
ScheduleTaskSchema,
|
|
428
|
+
ScopedUsageSummarySchema,
|
|
391
429
|
SearchResultSchema,
|
|
392
430
|
SessionMetadataSchema,
|
|
393
431
|
SessionSearchResponseSchema,
|
|
394
432
|
SessionSearchResultSchema,
|
|
395
433
|
SessionTokenUsageSchema,
|
|
434
|
+
SessionUsageTrackingSchema,
|
|
396
435
|
SseServerConfigSchema,
|
|
397
436
|
StandardErrorEnvelopeSchema,
|
|
398
437
|
StatusResponseSchema,
|
|
@@ -402,6 +441,7 @@ const DeleteResponseSchema = import_zod.z.object({
|
|
|
402
441
|
ToolCallSchema,
|
|
403
442
|
ToolSchema,
|
|
404
443
|
UIResourcePartSchema,
|
|
444
|
+
UsageSummarySchema,
|
|
405
445
|
WebhookSchema,
|
|
406
446
|
WorkspaceSchema
|
|
407
447
|
});
|