@dexto/server 1.3.0 → 1.4.0
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/approval/manual-approval-handler.cjs +23 -15
- package/dist/approval/manual-approval-handler.d.ts.map +1 -1
- package/dist/approval/manual-approval-handler.js +23 -15
- package/dist/events/webhook-subscriber.cjs +1 -1
- package/dist/events/webhook-subscriber.d.ts.map +1 -1
- package/dist/events/webhook-subscriber.js +1 -1
- package/dist/hono/__tests__/test-fixtures.cjs +2 -2
- package/dist/hono/__tests__/test-fixtures.d.ts.map +1 -1
- package/dist/hono/__tests__/test-fixtures.js +2 -2
- package/dist/hono/index.cjs +6 -1
- package/dist/hono/index.d.ts +433 -88
- package/dist/hono/index.d.ts.map +1 -1
- package/dist/hono/index.js +6 -1
- package/dist/hono/middleware/error.d.ts.map +1 -1
- package/dist/hono/routes/agents.cjs +8 -10
- package/dist/hono/routes/agents.d.ts +15 -8
- package/dist/hono/routes/agents.d.ts.map +1 -1
- package/dist/hono/routes/agents.js +10 -10
- package/dist/hono/routes/approvals.cjs +52 -1
- package/dist/hono/routes/approvals.d.ts +25 -0
- package/dist/hono/routes/approvals.d.ts.map +1 -1
- package/dist/hono/routes/approvals.js +52 -1
- package/dist/hono/routes/llm.cjs +110 -31
- package/dist/hono/routes/llm.d.ts +72 -20
- package/dist/hono/routes/llm.d.ts.map +1 -1
- package/dist/hono/routes/llm.js +108 -25
- package/dist/hono/routes/mcp.cjs +8 -4
- package/dist/hono/routes/mcp.d.ts +4 -1
- package/dist/hono/routes/mcp.d.ts.map +1 -1
- package/dist/hono/routes/mcp.js +9 -5
- package/dist/hono/routes/memory.d.ts +1 -1
- package/dist/hono/routes/messages.cjs +54 -62
- package/dist/hono/routes/messages.d.ts +87 -43
- package/dist/hono/routes/messages.d.ts.map +1 -1
- package/dist/hono/routes/messages.js +55 -63
- package/dist/hono/routes/prompts.d.ts +6 -6
- package/dist/hono/routes/queue.cjs +202 -0
- package/dist/hono/routes/queue.d.ts +171 -0
- package/dist/hono/routes/queue.d.ts.map +1 -0
- package/dist/hono/routes/queue.js +178 -0
- package/dist/hono/routes/resources.d.ts +1 -1
- package/dist/hono/routes/search.d.ts +33 -7
- package/dist/hono/routes/search.d.ts.map +1 -1
- package/dist/hono/routes/sessions.cjs +65 -11
- package/dist/hono/routes/sessions.d.ts +22 -1
- package/dist/hono/routes/sessions.d.ts.map +1 -1
- package/dist/hono/routes/sessions.js +65 -11
- package/dist/hono/schemas/responses.cjs +24 -5
- package/dist/hono/schemas/responses.d.ts +799 -81
- package/dist/hono/schemas/responses.d.ts.map +1 -1
- package/dist/hono/schemas/responses.js +24 -10
- package/package.json +3 -3
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
|
2
2
|
import { streamSSE } from "hono/streaming";
|
|
3
|
-
import { LLM_PROVIDERS
|
|
3
|
+
import { LLM_PROVIDERS } from "@dexto/core";
|
|
4
4
|
import { TokenUsageSchema } from "../schemas/responses.js";
|
|
5
|
+
const TextPartSchema = z.object({
|
|
6
|
+
type: z.literal("text").describe("Content type identifier"),
|
|
7
|
+
text: z.string().describe("Text content")
|
|
8
|
+
}).describe("Text content part");
|
|
9
|
+
const ImagePartSchema = z.object({
|
|
10
|
+
type: z.literal("image").describe("Content type identifier"),
|
|
11
|
+
image: z.string().describe("Base64-encoded image data or URL"),
|
|
12
|
+
mimeType: z.string().optional().describe("MIME type (e.g., image/png)")
|
|
13
|
+
}).describe("Image content part");
|
|
14
|
+
const FilePartSchema = z.object({
|
|
15
|
+
type: z.literal("file").describe("Content type identifier"),
|
|
16
|
+
data: z.string().describe("Base64-encoded file data or URL"),
|
|
17
|
+
mimeType: z.string().describe("MIME type (e.g., application/pdf)"),
|
|
18
|
+
filename: z.string().optional().describe("Optional filename")
|
|
19
|
+
}).describe("File content part");
|
|
20
|
+
const ContentPartSchema = z.discriminatedUnion("type", [TextPartSchema, ImagePartSchema, FilePartSchema]).describe("Content part - text, image, or file");
|
|
5
21
|
const MessageBodySchema = z.object({
|
|
6
|
-
|
|
7
|
-
sessionId: z.string().min(1, "Session ID is required").describe("The session to use for this message")
|
|
8
|
-
|
|
9
|
-
image: z.string().describe("Base64-encoded image data"),
|
|
10
|
-
mimeType: z.string().describe("The MIME type of the image (e.g., image/png)")
|
|
11
|
-
}).optional().describe("Optional image data to include with the message"),
|
|
12
|
-
fileData: z.object({
|
|
13
|
-
data: z.string().describe("Base64-encoded file data"),
|
|
14
|
-
mimeType: z.string().describe("The MIME type of the file (e.g., application/pdf)"),
|
|
15
|
-
filename: z.string().optional().describe("The filename")
|
|
16
|
-
}).optional().describe("Optional file data to include with the message")
|
|
17
|
-
}).refine(
|
|
18
|
-
(data) => {
|
|
19
|
-
const msg = (data.message ?? "").trim();
|
|
20
|
-
return msg.length > 0 || !!data.imageData || !!data.fileData;
|
|
21
|
-
},
|
|
22
|
-
{ message: "Must provide either message text, image data, or file data" }
|
|
23
|
-
).describe("Request body for sending a message to the agent");
|
|
22
|
+
content: z.union([z.string(), z.array(ContentPartSchema)]).describe("Message content - string for text, or ContentPart[] for multimodal"),
|
|
23
|
+
sessionId: z.string().min(1, "Session ID is required").describe("The session to use for this message")
|
|
24
|
+
}).describe("Request body for sending a message to the agent");
|
|
24
25
|
const ResetBodySchema = z.object({
|
|
25
26
|
sessionId: z.string().min(1, "Session ID is required").describe("The ID of the session to reset")
|
|
26
27
|
}).describe("Request body for resetting a conversation");
|
|
@@ -72,8 +73,7 @@ function createMessagesRouter(getAgent, approvalCoordinator) {
|
|
|
72
73
|
tokenUsage: TokenUsageSchema.optional().describe("Token usage statistics"),
|
|
73
74
|
reasoning: z.string().optional().describe("Extended thinking content from reasoning models"),
|
|
74
75
|
model: z.string().optional().describe("Model used for this response"),
|
|
75
|
-
provider: z.enum(LLM_PROVIDERS).optional().describe("LLM provider")
|
|
76
|
-
router: z.enum(LLM_ROUTERS).optional().describe("Router used (e.g., vercel)")
|
|
76
|
+
provider: z.enum(LLM_PROVIDERS).optional().describe("LLM provider")
|
|
77
77
|
}).strict()
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -108,7 +108,7 @@ function createMessagesRouter(getAgent, approvalCoordinator) {
|
|
|
108
108
|
method: "post",
|
|
109
109
|
path: "/message-stream",
|
|
110
110
|
summary: "Stream message response",
|
|
111
|
-
description: "Sends a message and streams the response via Server-Sent Events (SSE). Returns SSE stream directly in response. Events include llm:thinking, llm:chunk, llm:tool-call, llm:tool-result, llm:response, and llm:error.",
|
|
111
|
+
description: "Sends a message and streams the response via Server-Sent Events (SSE). Returns SSE stream directly in response. Events include llm:thinking, llm:chunk, llm:tool-call, llm:tool-result, llm:response, and llm:error. If the session is busy processing another message, returns 202 with queue information.",
|
|
112
112
|
tags: ["messages"],
|
|
113
113
|
request: {
|
|
114
114
|
body: {
|
|
@@ -144,23 +144,28 @@ function createMessagesRouter(getAgent, approvalCoordinator) {
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
},
|
|
147
|
+
202: {
|
|
148
|
+
description: "Session is busy processing another message. Use the queue endpoints to manage pending messages.",
|
|
149
|
+
content: {
|
|
150
|
+
"application/json": {
|
|
151
|
+
schema: z.object({
|
|
152
|
+
busy: z.literal(true).describe("Indicates session is busy"),
|
|
153
|
+
sessionId: z.string().describe("The session ID"),
|
|
154
|
+
queueLength: z.number().describe("Current number of messages in queue"),
|
|
155
|
+
hint: z.string().describe("Instructions for the client")
|
|
156
|
+
}).strict()
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
},
|
|
147
160
|
400: { description: "Validation error" }
|
|
148
161
|
}
|
|
149
162
|
});
|
|
150
163
|
return app.openapi(messageRoute, async (ctx) => {
|
|
151
164
|
const agent = getAgent();
|
|
152
165
|
agent.logger.info("Received message via POST /api/message");
|
|
153
|
-
const {
|
|
154
|
-
const imageDataInput = imageData ? { image: imageData.image, mimeType: imageData.mimeType } : void 0;
|
|
155
|
-
const fileDataInput = fileData ? {
|
|
156
|
-
data: fileData.data,
|
|
157
|
-
mimeType: fileData.mimeType,
|
|
158
|
-
...fileData.filename && { filename: fileData.filename }
|
|
159
|
-
} : void 0;
|
|
160
|
-
if (imageDataInput) agent.logger.info("Image data included in message.");
|
|
161
|
-
if (fileDataInput) agent.logger.info("File data included in message.");
|
|
166
|
+
const { content, sessionId } = ctx.req.valid("json");
|
|
162
167
|
agent.logger.info(`Message for session: ${sessionId}`);
|
|
163
|
-
agent.
|
|
168
|
+
agent.generate(content, sessionId).catch((error) => {
|
|
164
169
|
agent.logger.error(
|
|
165
170
|
`Error in async message processing: ${error instanceof Error ? error.message : String(error)}`
|
|
166
171
|
);
|
|
@@ -169,21 +174,9 @@ function createMessagesRouter(getAgent, approvalCoordinator) {
|
|
|
169
174
|
}).openapi(messageSyncRoute, async (ctx) => {
|
|
170
175
|
const agent = getAgent();
|
|
171
176
|
agent.logger.info("Received message via POST /api/message-sync");
|
|
172
|
-
const {
|
|
173
|
-
const imageDataInput = imageData ? { image: imageData.image, mimeType: imageData.mimeType } : void 0;
|
|
174
|
-
const fileDataInput = fileData ? {
|
|
175
|
-
data: fileData.data,
|
|
176
|
-
mimeType: fileData.mimeType,
|
|
177
|
-
...fileData.filename && { filename: fileData.filename }
|
|
178
|
-
} : void 0;
|
|
179
|
-
if (imageDataInput) agent.logger.info("Image data included in message.");
|
|
180
|
-
if (fileDataInput) agent.logger.info("File data included in message.");
|
|
177
|
+
const { content, sessionId } = ctx.req.valid("json");
|
|
181
178
|
agent.logger.info(`Message for session: ${sessionId}`);
|
|
182
|
-
const result = await agent.generate(
|
|
183
|
-
sessionId,
|
|
184
|
-
imageData: imageDataInput,
|
|
185
|
-
fileData: fileDataInput
|
|
186
|
-
});
|
|
179
|
+
const result = await agent.generate(content, sessionId);
|
|
187
180
|
const llmConfig = agent.stateManager.getLLMConfig(sessionId);
|
|
188
181
|
return ctx.json({
|
|
189
182
|
response: result.content,
|
|
@@ -191,9 +184,7 @@ function createMessagesRouter(getAgent, approvalCoordinator) {
|
|
|
191
184
|
tokenUsage: result.usage,
|
|
192
185
|
reasoning: result.reasoning,
|
|
193
186
|
model: llmConfig.model,
|
|
194
|
-
provider: llmConfig.provider
|
|
195
|
-
router: "vercel"
|
|
196
|
-
// Hardcoded for now since we only use Vercel AI SDK
|
|
187
|
+
provider: llmConfig.provider
|
|
197
188
|
});
|
|
198
189
|
}).openapi(resetRoute, async (ctx) => {
|
|
199
190
|
const agent = getAgent();
|
|
@@ -203,22 +194,23 @@ function createMessagesRouter(getAgent, approvalCoordinator) {
|
|
|
203
194
|
return ctx.json({ status: "reset initiated", sessionId });
|
|
204
195
|
}).openapi(messageStreamRoute, async (ctx) => {
|
|
205
196
|
const agent = getAgent();
|
|
206
|
-
const
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
197
|
+
const { content, sessionId } = ctx.req.valid("json");
|
|
198
|
+
const isBusy = await agent.isSessionBusy(sessionId);
|
|
199
|
+
if (isBusy) {
|
|
200
|
+
const queuedMessages = await agent.getQueuedMessages(sessionId);
|
|
201
|
+
return ctx.json(
|
|
202
|
+
{
|
|
203
|
+
busy: true,
|
|
204
|
+
sessionId,
|
|
205
|
+
queueLength: queuedMessages.length,
|
|
206
|
+
hint: "Use POST /api/queue/{sessionId} to queue this message, or wait for the current request to complete."
|
|
207
|
+
},
|
|
208
|
+
202
|
|
209
|
+
);
|
|
210
|
+
}
|
|
214
211
|
const abortController = new AbortController();
|
|
215
212
|
const { signal } = abortController;
|
|
216
|
-
const iterator = await agent.stream(
|
|
217
|
-
sessionId,
|
|
218
|
-
imageData: imageDataInput,
|
|
219
|
-
fileData: fileDataInput,
|
|
220
|
-
signal
|
|
221
|
-
});
|
|
213
|
+
const iterator = await agent.stream(content, sessionId, { signal });
|
|
222
214
|
return streamSSE(ctx, async (stream) => {
|
|
223
215
|
const pendingApprovalEvents = [];
|
|
224
216
|
if (approvalCoordinator) {
|
|
@@ -10,14 +10,14 @@ export declare function createPromptsRouter(getAgent: () => DextoAgent): OpenAPI
|
|
|
10
10
|
source: "config" | "custom" | "mcp";
|
|
11
11
|
description?: string | undefined;
|
|
12
12
|
title?: string | undefined;
|
|
13
|
+
metadata?: {
|
|
14
|
+
[x: string]: import("hono/utils/types").JSONValue;
|
|
15
|
+
} | undefined;
|
|
13
16
|
arguments?: {
|
|
14
17
|
name: string;
|
|
15
18
|
description?: string | undefined;
|
|
16
19
|
required?: boolean | undefined;
|
|
17
20
|
}[] | undefined;
|
|
18
|
-
metadata?: {
|
|
19
|
-
[x: string]: import("hono/utils/types").JSONValue;
|
|
20
|
-
} | undefined;
|
|
21
21
|
}[];
|
|
22
22
|
};
|
|
23
23
|
outputFormat: "json";
|
|
@@ -51,14 +51,14 @@ export declare function createPromptsRouter(getAgent: () => DextoAgent): OpenAPI
|
|
|
51
51
|
source: "config" | "custom" | "mcp";
|
|
52
52
|
description?: string | undefined;
|
|
53
53
|
title?: string | undefined;
|
|
54
|
+
metadata?: {
|
|
55
|
+
[x: string]: import("hono/utils/types").JSONValue;
|
|
56
|
+
} | undefined;
|
|
54
57
|
arguments?: {
|
|
55
58
|
name: string;
|
|
56
59
|
description?: string | undefined;
|
|
57
60
|
required?: boolean | undefined;
|
|
58
61
|
}[] | undefined;
|
|
59
|
-
metadata?: {
|
|
60
|
-
[x: string]: import("hono/utils/types").JSONValue;
|
|
61
|
-
} | undefined;
|
|
62
62
|
};
|
|
63
63
|
};
|
|
64
64
|
outputFormat: "json";
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var queue_exports = {};
|
|
20
|
+
__export(queue_exports, {
|
|
21
|
+
createQueueRouter: () => createQueueRouter
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(queue_exports);
|
|
24
|
+
var import_zod_openapi = require("@hono/zod-openapi");
|
|
25
|
+
var import_responses = require("../schemas/responses.js");
|
|
26
|
+
const QueuedMessageSchema = import_zod_openapi.z.object({
|
|
27
|
+
id: import_zod_openapi.z.string().describe("Unique identifier for the queued message"),
|
|
28
|
+
content: import_zod_openapi.z.array(import_responses.ContentPartSchema).describe("Message content parts"),
|
|
29
|
+
queuedAt: import_zod_openapi.z.number().describe("Unix timestamp when message was queued"),
|
|
30
|
+
metadata: import_zod_openapi.z.record(import_zod_openapi.z.unknown()).optional().describe("Optional metadata")
|
|
31
|
+
}).strict().describe("A message waiting in the queue");
|
|
32
|
+
const TextPartSchema = import_zod_openapi.z.object({
|
|
33
|
+
type: import_zod_openapi.z.literal("text").describe("Content type identifier"),
|
|
34
|
+
text: import_zod_openapi.z.string().describe("Text content")
|
|
35
|
+
}).describe("Text content part");
|
|
36
|
+
const ImagePartSchema = import_zod_openapi.z.object({
|
|
37
|
+
type: import_zod_openapi.z.literal("image").describe("Content type identifier"),
|
|
38
|
+
image: import_zod_openapi.z.string().describe("Base64-encoded image data or URL"),
|
|
39
|
+
mimeType: import_zod_openapi.z.string().optional().describe("MIME type (e.g., image/png)")
|
|
40
|
+
}).describe("Image content part");
|
|
41
|
+
const FilePartSchema = import_zod_openapi.z.object({
|
|
42
|
+
type: import_zod_openapi.z.literal("file").describe("Content type identifier"),
|
|
43
|
+
data: import_zod_openapi.z.string().describe("Base64-encoded file data or URL"),
|
|
44
|
+
mimeType: import_zod_openapi.z.string().describe("MIME type (e.g., application/pdf)"),
|
|
45
|
+
filename: import_zod_openapi.z.string().optional().describe("Optional filename")
|
|
46
|
+
}).describe("File content part");
|
|
47
|
+
const QueueContentPartSchema = import_zod_openapi.z.discriminatedUnion("type", [TextPartSchema, ImagePartSchema, FilePartSchema]).describe("Content part - text, image, or file");
|
|
48
|
+
const QueueMessageBodySchema = import_zod_openapi.z.object({
|
|
49
|
+
content: import_zod_openapi.z.union([import_zod_openapi.z.string(), import_zod_openapi.z.array(QueueContentPartSchema)]).describe("Message content - string for text, or ContentPart[] for multimodal")
|
|
50
|
+
}).describe("Request body for queueing a message");
|
|
51
|
+
function createQueueRouter(getAgent) {
|
|
52
|
+
const app = new import_zod_openapi.OpenAPIHono();
|
|
53
|
+
const getQueueRoute = (0, import_zod_openapi.createRoute)({
|
|
54
|
+
method: "get",
|
|
55
|
+
path: "/queue/{sessionId}",
|
|
56
|
+
summary: "Get queued messages",
|
|
57
|
+
description: "Returns all messages waiting in the queue for a session",
|
|
58
|
+
tags: ["queue"],
|
|
59
|
+
request: {
|
|
60
|
+
params: import_zod_openapi.z.object({
|
|
61
|
+
sessionId: import_zod_openapi.z.string().min(1).describe("Session ID")
|
|
62
|
+
})
|
|
63
|
+
},
|
|
64
|
+
responses: {
|
|
65
|
+
200: {
|
|
66
|
+
description: "List of queued messages",
|
|
67
|
+
content: {
|
|
68
|
+
"application/json": {
|
|
69
|
+
schema: import_zod_openapi.z.object({
|
|
70
|
+
messages: import_zod_openapi.z.array(QueuedMessageSchema).describe("Queued messages"),
|
|
71
|
+
count: import_zod_openapi.z.number().describe("Number of messages in queue")
|
|
72
|
+
}).strict()
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
404: { description: "Session not found" }
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
const queueMessageRoute = (0, import_zod_openapi.createRoute)({
|
|
80
|
+
method: "post",
|
|
81
|
+
path: "/queue/{sessionId}",
|
|
82
|
+
summary: "Queue a message",
|
|
83
|
+
description: "Adds a message to the queue for processing when the session is no longer busy",
|
|
84
|
+
tags: ["queue"],
|
|
85
|
+
request: {
|
|
86
|
+
params: import_zod_openapi.z.object({
|
|
87
|
+
sessionId: import_zod_openapi.z.string().min(1).describe("Session ID")
|
|
88
|
+
}),
|
|
89
|
+
body: {
|
|
90
|
+
content: { "application/json": { schema: QueueMessageBodySchema } }
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
responses: {
|
|
94
|
+
201: {
|
|
95
|
+
description: "Message queued successfully",
|
|
96
|
+
content: {
|
|
97
|
+
"application/json": {
|
|
98
|
+
schema: import_zod_openapi.z.object({
|
|
99
|
+
queued: import_zod_openapi.z.literal(true).describe("Indicates message was queued"),
|
|
100
|
+
id: import_zod_openapi.z.string().describe("ID of the queued message"),
|
|
101
|
+
position: import_zod_openapi.z.number().describe("Position in the queue (1-based)")
|
|
102
|
+
}).strict()
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
404: { description: "Session not found" }
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
const removeQueuedMessageRoute = (0, import_zod_openapi.createRoute)({
|
|
110
|
+
method: "delete",
|
|
111
|
+
path: "/queue/{sessionId}/{messageId}",
|
|
112
|
+
summary: "Remove queued message",
|
|
113
|
+
description: "Removes a specific message from the queue",
|
|
114
|
+
tags: ["queue"],
|
|
115
|
+
request: {
|
|
116
|
+
params: import_zod_openapi.z.object({
|
|
117
|
+
sessionId: import_zod_openapi.z.string().min(1).describe("Session ID"),
|
|
118
|
+
messageId: import_zod_openapi.z.string().min(1).describe("ID of the queued message to remove")
|
|
119
|
+
})
|
|
120
|
+
},
|
|
121
|
+
responses: {
|
|
122
|
+
200: {
|
|
123
|
+
description: "Message removed successfully",
|
|
124
|
+
content: {
|
|
125
|
+
"application/json": {
|
|
126
|
+
schema: import_zod_openapi.z.object({
|
|
127
|
+
removed: import_zod_openapi.z.literal(true).describe("Indicates message was removed"),
|
|
128
|
+
id: import_zod_openapi.z.string().describe("ID of the removed message")
|
|
129
|
+
}).strict()
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
404: { description: "Session or message not found" }
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
const clearQueueRoute = (0, import_zod_openapi.createRoute)({
|
|
137
|
+
method: "delete",
|
|
138
|
+
path: "/queue/{sessionId}",
|
|
139
|
+
summary: "Clear message queue",
|
|
140
|
+
description: "Removes all messages from the queue for a session",
|
|
141
|
+
tags: ["queue"],
|
|
142
|
+
request: {
|
|
143
|
+
params: import_zod_openapi.z.object({
|
|
144
|
+
sessionId: import_zod_openapi.z.string().min(1).describe("Session ID")
|
|
145
|
+
})
|
|
146
|
+
},
|
|
147
|
+
responses: {
|
|
148
|
+
200: {
|
|
149
|
+
description: "Queue cleared successfully",
|
|
150
|
+
content: {
|
|
151
|
+
"application/json": {
|
|
152
|
+
schema: import_zod_openapi.z.object({
|
|
153
|
+
cleared: import_zod_openapi.z.literal(true).describe("Indicates queue was cleared"),
|
|
154
|
+
count: import_zod_openapi.z.number().describe("Number of messages that were removed")
|
|
155
|
+
}).strict()
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
404: { description: "Session not found" }
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
return app.openapi(getQueueRoute, async (ctx) => {
|
|
163
|
+
const agent = getAgent();
|
|
164
|
+
const { sessionId } = ctx.req.valid("param");
|
|
165
|
+
const messages = await agent.getQueuedMessages(sessionId);
|
|
166
|
+
return ctx.json({
|
|
167
|
+
messages,
|
|
168
|
+
count: messages.length
|
|
169
|
+
});
|
|
170
|
+
}).openapi(queueMessageRoute, async (ctx) => {
|
|
171
|
+
const agent = getAgent();
|
|
172
|
+
const { sessionId } = ctx.req.valid("param");
|
|
173
|
+
const { content: rawContent } = ctx.req.valid("json");
|
|
174
|
+
const content = typeof rawContent === "string" ? [{ type: "text", text: rawContent }] : rawContent;
|
|
175
|
+
const result = await agent.queueMessage(sessionId, { content });
|
|
176
|
+
return ctx.json(
|
|
177
|
+
{
|
|
178
|
+
queued: result.queued,
|
|
179
|
+
id: result.id,
|
|
180
|
+
position: result.position
|
|
181
|
+
},
|
|
182
|
+
201
|
|
183
|
+
);
|
|
184
|
+
}).openapi(removeQueuedMessageRoute, async (ctx) => {
|
|
185
|
+
const agent = getAgent();
|
|
186
|
+
const { sessionId, messageId } = ctx.req.valid("param");
|
|
187
|
+
const removed = await agent.removeQueuedMessage(sessionId, messageId);
|
|
188
|
+
if (!removed) {
|
|
189
|
+
return ctx.json({ error: "Message not found in queue" }, 404);
|
|
190
|
+
}
|
|
191
|
+
return ctx.json({ removed: true, id: messageId });
|
|
192
|
+
}).openapi(clearQueueRoute, async (ctx) => {
|
|
193
|
+
const agent = getAgent();
|
|
194
|
+
const { sessionId } = ctx.req.valid("param");
|
|
195
|
+
const count = await agent.clearMessageQueue(sessionId);
|
|
196
|
+
return ctx.json({ cleared: true, count });
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
200
|
+
0 && (module.exports = {
|
|
201
|
+
createQueueRouter
|
|
202
|
+
});
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { OpenAPIHono } from '@hono/zod-openapi';
|
|
2
|
+
import type { DextoAgent } from '@dexto/core';
|
|
3
|
+
export declare function createQueueRouter(getAgent: () => DextoAgent): OpenAPIHono<import("hono").Env, {
|
|
4
|
+
"/queue/:sessionId": {
|
|
5
|
+
$get: {
|
|
6
|
+
input: {
|
|
7
|
+
param: {
|
|
8
|
+
sessionId: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
output: {};
|
|
12
|
+
outputFormat: string;
|
|
13
|
+
status: 404;
|
|
14
|
+
} | {
|
|
15
|
+
input: {
|
|
16
|
+
param: {
|
|
17
|
+
sessionId: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
output: {
|
|
21
|
+
messages: {
|
|
22
|
+
content: ({
|
|
23
|
+
type: "text";
|
|
24
|
+
text: string;
|
|
25
|
+
} | {
|
|
26
|
+
type: "image";
|
|
27
|
+
image: string;
|
|
28
|
+
mimeType?: string | undefined;
|
|
29
|
+
} | {
|
|
30
|
+
type: "file";
|
|
31
|
+
mimeType: string;
|
|
32
|
+
data: string;
|
|
33
|
+
filename?: string | undefined;
|
|
34
|
+
} | {
|
|
35
|
+
type: "ui-resource";
|
|
36
|
+
mimeType: string;
|
|
37
|
+
uri: string;
|
|
38
|
+
content?: string | undefined;
|
|
39
|
+
blob?: string | undefined;
|
|
40
|
+
metadata?: {
|
|
41
|
+
title?: string | undefined;
|
|
42
|
+
preferredSize?: {
|
|
43
|
+
width: number;
|
|
44
|
+
height: number;
|
|
45
|
+
} | undefined;
|
|
46
|
+
} | undefined;
|
|
47
|
+
})[];
|
|
48
|
+
id: string;
|
|
49
|
+
queuedAt: number;
|
|
50
|
+
metadata?: {
|
|
51
|
+
[x: string]: import("hono/utils/types").JSONValue;
|
|
52
|
+
} | undefined;
|
|
53
|
+
}[];
|
|
54
|
+
count: number;
|
|
55
|
+
};
|
|
56
|
+
outputFormat: "json";
|
|
57
|
+
status: 200;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
} & {
|
|
61
|
+
"/queue/:sessionId": {
|
|
62
|
+
$post: {
|
|
63
|
+
input: {
|
|
64
|
+
param: {
|
|
65
|
+
sessionId: string;
|
|
66
|
+
};
|
|
67
|
+
} & {
|
|
68
|
+
json: {
|
|
69
|
+
content: string | ({
|
|
70
|
+
type: "text";
|
|
71
|
+
text: string;
|
|
72
|
+
} | {
|
|
73
|
+
type: "image";
|
|
74
|
+
image: string;
|
|
75
|
+
mimeType?: string | undefined;
|
|
76
|
+
} | {
|
|
77
|
+
type: "file";
|
|
78
|
+
mimeType: string;
|
|
79
|
+
data: string;
|
|
80
|
+
filename?: string | undefined;
|
|
81
|
+
})[];
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
output: {};
|
|
85
|
+
outputFormat: string;
|
|
86
|
+
status: 404;
|
|
87
|
+
} | {
|
|
88
|
+
input: {
|
|
89
|
+
param: {
|
|
90
|
+
sessionId: string;
|
|
91
|
+
};
|
|
92
|
+
} & {
|
|
93
|
+
json: {
|
|
94
|
+
content: string | ({
|
|
95
|
+
type: "text";
|
|
96
|
+
text: string;
|
|
97
|
+
} | {
|
|
98
|
+
type: "image";
|
|
99
|
+
image: string;
|
|
100
|
+
mimeType?: string | undefined;
|
|
101
|
+
} | {
|
|
102
|
+
type: "file";
|
|
103
|
+
mimeType: string;
|
|
104
|
+
data: string;
|
|
105
|
+
filename?: string | undefined;
|
|
106
|
+
})[];
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
output: {
|
|
110
|
+
id: string;
|
|
111
|
+
queued: true;
|
|
112
|
+
position: number;
|
|
113
|
+
};
|
|
114
|
+
outputFormat: "json";
|
|
115
|
+
status: 201;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
} & {
|
|
119
|
+
"/queue/:sessionId/:messageId": {
|
|
120
|
+
$delete: {
|
|
121
|
+
input: {
|
|
122
|
+
param: {
|
|
123
|
+
sessionId: string;
|
|
124
|
+
messageId: string;
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
output: {};
|
|
128
|
+
outputFormat: string;
|
|
129
|
+
status: 404;
|
|
130
|
+
} | {
|
|
131
|
+
input: {
|
|
132
|
+
param: {
|
|
133
|
+
sessionId: string;
|
|
134
|
+
messageId: string;
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
output: {
|
|
138
|
+
id: string;
|
|
139
|
+
removed: true;
|
|
140
|
+
};
|
|
141
|
+
outputFormat: "json";
|
|
142
|
+
status: 200;
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
} & {
|
|
146
|
+
"/queue/:sessionId": {
|
|
147
|
+
$delete: {
|
|
148
|
+
input: {
|
|
149
|
+
param: {
|
|
150
|
+
sessionId: string;
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
output: {};
|
|
154
|
+
outputFormat: string;
|
|
155
|
+
status: 404;
|
|
156
|
+
} | {
|
|
157
|
+
input: {
|
|
158
|
+
param: {
|
|
159
|
+
sessionId: string;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
output: {
|
|
163
|
+
count: number;
|
|
164
|
+
cleared: true;
|
|
165
|
+
};
|
|
166
|
+
outputFormat: "json";
|
|
167
|
+
status: 200;
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
}, "/">;
|
|
171
|
+
//# sourceMappingURL=queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../../src/hono/routes/queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAe,MAAM,aAAa,CAAC;AAsD3D,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAoL3D"}
|