@dexto/server 1.2.5
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/LICENSE +44 -0
- package/dist/a2a/adapters/index.cjs +42 -0
- package/dist/a2a/adapters/index.d.ts +10 -0
- package/dist/a2a/adapters/index.d.ts.map +1 -0
- package/dist/a2a/adapters/index.js +12 -0
- package/dist/a2a/adapters/message.cjs +193 -0
- package/dist/a2a/adapters/message.d.ts +50 -0
- package/dist/a2a/adapters/message.d.ts.map +1 -0
- package/dist/a2a/adapters/message.js +167 -0
- package/dist/a2a/adapters/state.cjs +57 -0
- package/dist/a2a/adapters/state.d.ts +36 -0
- package/dist/a2a/adapters/state.d.ts.map +1 -0
- package/dist/a2a/adapters/state.js +32 -0
- package/dist/a2a/adapters/task-view.cjs +85 -0
- package/dist/a2a/adapters/task-view.d.ts +58 -0
- package/dist/a2a/adapters/task-view.d.ts.map +1 -0
- package/dist/a2a/adapters/task-view.js +60 -0
- package/dist/a2a/index.cjs +51 -0
- package/dist/a2a/index.d.ts +15 -0
- package/dist/a2a/index.d.ts.map +1 -0
- package/dist/a2a/index.js +30 -0
- package/dist/a2a/jsonrpc/index.cjs +38 -0
- package/dist/a2a/jsonrpc/index.d.ts +11 -0
- package/dist/a2a/jsonrpc/index.d.ts.map +1 -0
- package/dist/a2a/jsonrpc/index.js +10 -0
- package/dist/a2a/jsonrpc/methods.cjs +183 -0
- package/dist/a2a/jsonrpc/methods.d.ts +110 -0
- package/dist/a2a/jsonrpc/methods.d.ts.map +1 -0
- package/dist/a2a/jsonrpc/methods.js +159 -0
- package/dist/a2a/jsonrpc/server.cjs +199 -0
- package/dist/a2a/jsonrpc/server.d.ts +100 -0
- package/dist/a2a/jsonrpc/server.d.ts.map +1 -0
- package/dist/a2a/jsonrpc/server.js +175 -0
- package/dist/a2a/jsonrpc/types.cjs +47 -0
- package/dist/a2a/jsonrpc/types.d.ts +91 -0
- package/dist/a2a/jsonrpc/types.d.ts.map +1 -0
- package/dist/a2a/jsonrpc/types.js +21 -0
- package/dist/a2a/types.cjs +16 -0
- package/dist/a2a/types.d.ts +250 -0
- package/dist/a2a/types.d.ts.map +1 -0
- package/dist/a2a/types.js +0 -0
- package/dist/approval/approval-coordinator.cjs +87 -0
- package/dist/approval/approval-coordinator.d.ts +52 -0
- package/dist/approval/approval-coordinator.d.ts.map +1 -0
- package/dist/approval/approval-coordinator.js +63 -0
- package/dist/approval/manual-approval-handler.cjs +100 -0
- package/dist/approval/manual-approval-handler.d.ts +32 -0
- package/dist/approval/manual-approval-handler.d.ts.map +1 -0
- package/dist/approval/manual-approval-handler.js +76 -0
- package/dist/events/a2a-sse-subscriber.cjs +271 -0
- package/dist/events/a2a-sse-subscriber.d.ts +94 -0
- package/dist/events/a2a-sse-subscriber.d.ts.map +1 -0
- package/dist/events/a2a-sse-subscriber.js +247 -0
- package/dist/events/types.cjs +16 -0
- package/dist/events/types.d.ts +15 -0
- package/dist/events/types.d.ts.map +1 -0
- package/dist/events/types.js +0 -0
- package/dist/events/webhook-subscriber.cjs +301 -0
- package/dist/events/webhook-subscriber.d.ts +64 -0
- package/dist/events/webhook-subscriber.d.ts.map +1 -0
- package/dist/events/webhook-subscriber.js +269 -0
- package/dist/events/webhook-types.cjs +16 -0
- package/dist/events/webhook-types.d.ts +91 -0
- package/dist/events/webhook-types.d.ts.map +1 -0
- package/dist/events/webhook-types.js +0 -0
- package/dist/hono/__tests__/test-fixtures.cjs +236 -0
- package/dist/hono/__tests__/test-fixtures.d.ts +65 -0
- package/dist/hono/__tests__/test-fixtures.d.ts.map +1 -0
- package/dist/hono/__tests__/test-fixtures.js +197 -0
- package/dist/hono/index.cjs +166 -0
- package/dist/hono/index.d.ts +2783 -0
- package/dist/hono/index.d.ts.map +1 -0
- package/dist/hono/index.js +141 -0
- package/dist/hono/middleware/auth.cjs +75 -0
- package/dist/hono/middleware/auth.d.ts +3 -0
- package/dist/hono/middleware/auth.d.ts.map +1 -0
- package/dist/hono/middleware/auth.js +51 -0
- package/dist/hono/middleware/cors.cjs +57 -0
- package/dist/hono/middleware/cors.d.ts +9 -0
- package/dist/hono/middleware/cors.d.ts.map +1 -0
- package/dist/hono/middleware/cors.js +33 -0
- package/dist/hono/middleware/error.cjs +131 -0
- package/dist/hono/middleware/error.d.ts +5 -0
- package/dist/hono/middleware/error.d.ts.map +1 -0
- package/dist/hono/middleware/error.js +105 -0
- package/dist/hono/middleware/redaction.cjs +45 -0
- package/dist/hono/middleware/redaction.d.ts +4 -0
- package/dist/hono/middleware/redaction.d.ts.map +1 -0
- package/dist/hono/middleware/redaction.js +20 -0
- package/dist/hono/node/index.cjs +139 -0
- package/dist/hono/node/index.d.ts +19 -0
- package/dist/hono/node/index.d.ts.map +1 -0
- package/dist/hono/node/index.js +115 -0
- package/dist/hono/routes/a2a-jsonrpc.cjs +119 -0
- package/dist/hono/routes/a2a-jsonrpc.d.ts +46 -0
- package/dist/hono/routes/a2a-jsonrpc.d.ts.map +1 -0
- package/dist/hono/routes/a2a-jsonrpc.js +95 -0
- package/dist/hono/routes/a2a-tasks.cjs +315 -0
- package/dist/hono/routes/a2a-tasks.d.ts +530 -0
- package/dist/hono/routes/a2a-tasks.d.ts.map +1 -0
- package/dist/hono/routes/a2a-tasks.js +291 -0
- package/dist/hono/routes/a2a.cjs +36 -0
- package/dist/hono/routes/a2a.d.ts +4 -0
- package/dist/hono/routes/a2a.d.ts.map +1 -0
- package/dist/hono/routes/a2a.js +12 -0
- package/dist/hono/routes/agents.cjs +735 -0
- package/dist/hono/routes/agents.d.ts +650 -0
- package/dist/hono/routes/agents.d.ts.map +1 -0
- package/dist/hono/routes/agents.js +711 -0
- package/dist/hono/routes/approvals.cjs +125 -0
- package/dist/hono/routes/approvals.d.ts +89 -0
- package/dist/hono/routes/approvals.d.ts.map +1 -0
- package/dist/hono/routes/approvals.js +101 -0
- package/dist/hono/routes/greeting.cjs +60 -0
- package/dist/hono/routes/greeting.d.ts +19 -0
- package/dist/hono/routes/greeting.d.ts.map +1 -0
- package/dist/hono/routes/greeting.js +36 -0
- package/dist/hono/routes/health.cjs +45 -0
- package/dist/hono/routes/health.d.ts +17 -0
- package/dist/hono/routes/health.d.ts.map +1 -0
- package/dist/hono/routes/health.js +21 -0
- package/dist/hono/routes/llm.cjs +298 -0
- package/dist/hono/routes/llm.d.ts +294 -0
- package/dist/hono/routes/llm.d.ts.map +1 -0
- package/dist/hono/routes/llm.js +287 -0
- package/dist/hono/routes/mcp.cjs +356 -0
- package/dist/hono/routes/mcp.d.ts +246 -0
- package/dist/hono/routes/mcp.d.ts.map +1 -0
- package/dist/hono/routes/mcp.js +332 -0
- package/dist/hono/routes/memory.cjs +192 -0
- package/dist/hono/routes/memory.d.ts +146 -0
- package/dist/hono/routes/memory.d.ts.map +1 -0
- package/dist/hono/routes/memory.js +168 -0
- package/dist/hono/routes/messages.cjs +320 -0
- package/dist/hono/routes/messages.d.ts +163 -0
- package/dist/hono/routes/messages.d.ts.map +1 -0
- package/dist/hono/routes/messages.js +296 -0
- package/dist/hono/routes/prompts.cjs +228 -0
- package/dist/hono/routes/prompts.d.ts +150 -0
- package/dist/hono/routes/prompts.d.ts.map +1 -0
- package/dist/hono/routes/prompts.js +204 -0
- package/dist/hono/routes/resources.cjs +110 -0
- package/dist/hono/routes/resources.d.ts +76 -0
- package/dist/hono/routes/resources.d.ts.map +1 -0
- package/dist/hono/routes/resources.js +86 -0
- package/dist/hono/routes/search.cjs +109 -0
- package/dist/hono/routes/search.d.ts +137 -0
- package/dist/hono/routes/search.d.ts.map +1 -0
- package/dist/hono/routes/search.js +85 -0
- package/dist/hono/routes/sessions.cjs +366 -0
- package/dist/hono/routes/sessions.d.ts +229 -0
- package/dist/hono/routes/sessions.d.ts.map +1 -0
- package/dist/hono/routes/sessions.js +342 -0
- package/dist/hono/routes/webhooks.cjs +228 -0
- package/dist/hono/routes/webhooks.d.ts +127 -0
- package/dist/hono/routes/webhooks.d.ts.map +1 -0
- package/dist/hono/routes/webhooks.js +204 -0
- package/dist/hono/schemas/responses.cjs +276 -0
- package/dist/hono/schemas/responses.d.ts +1418 -0
- package/dist/hono/schemas/responses.d.ts.map +1 -0
- package/dist/hono/schemas/responses.js +227 -0
- package/dist/hono/types.cjs +16 -0
- package/dist/hono/types.d.ts +6 -0
- package/dist/hono/types.d.ts.map +1 -0
- package/dist/hono/types.js +0 -0
- package/dist/index.cjs +38 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/mcp/mcp-handler.cjs +145 -0
- package/dist/mcp/mcp-handler.d.ts +14 -0
- package/dist/mcp/mcp-handler.d.ts.map +1 -0
- package/dist/mcp/mcp-handler.js +118 -0
- package/package.json +59 -0
|
@@ -0,0 +1,320 @@
|
|
|
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 messages_exports = {};
|
|
20
|
+
__export(messages_exports, {
|
|
21
|
+
createMessagesRouter: () => createMessagesRouter
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(messages_exports);
|
|
24
|
+
var import_zod_openapi = require("@hono/zod-openapi");
|
|
25
|
+
var import_streaming = require("hono/streaming");
|
|
26
|
+
var import_core = require("@dexto/core");
|
|
27
|
+
var import_responses = require("../schemas/responses.js");
|
|
28
|
+
const MessageBodySchema = import_zod_openapi.z.object({
|
|
29
|
+
message: import_zod_openapi.z.string().optional().describe("The user message text"),
|
|
30
|
+
sessionId: import_zod_openapi.z.string().min(1, "Session ID is required").describe("The session to use for this message"),
|
|
31
|
+
imageData: import_zod_openapi.z.object({
|
|
32
|
+
base64: import_zod_openapi.z.string().describe("Base64-encoded image data"),
|
|
33
|
+
mimeType: import_zod_openapi.z.string().describe("The MIME type of the image (e.g., image/png)")
|
|
34
|
+
}).optional().describe("Optional image data to include with the message"),
|
|
35
|
+
fileData: import_zod_openapi.z.object({
|
|
36
|
+
base64: import_zod_openapi.z.string().describe("Base64-encoded file data"),
|
|
37
|
+
mimeType: import_zod_openapi.z.string().describe("The MIME type of the file (e.g., application/pdf)"),
|
|
38
|
+
filename: import_zod_openapi.z.string().optional().describe("The filename")
|
|
39
|
+
}).optional().describe("Optional file data to include with the message")
|
|
40
|
+
}).refine(
|
|
41
|
+
(data) => {
|
|
42
|
+
const msg = (data.message ?? "").trim();
|
|
43
|
+
return msg.length > 0 || !!data.imageData || !!data.fileData;
|
|
44
|
+
},
|
|
45
|
+
{ message: "Must provide either message text, image data, or file data" }
|
|
46
|
+
).describe("Request body for sending a message to the agent");
|
|
47
|
+
const ResetBodySchema = import_zod_openapi.z.object({
|
|
48
|
+
sessionId: import_zod_openapi.z.string().min(1, "Session ID is required").describe("The ID of the session to reset")
|
|
49
|
+
}).describe("Request body for resetting a conversation");
|
|
50
|
+
function createMessagesRouter(getAgent, approvalCoordinator) {
|
|
51
|
+
const app = new import_zod_openapi.OpenAPIHono();
|
|
52
|
+
const messageRoute = (0, import_zod_openapi.createRoute)({
|
|
53
|
+
method: "post",
|
|
54
|
+
path: "/message",
|
|
55
|
+
summary: "Send Message (async)",
|
|
56
|
+
description: "Sends a message and returns immediately. The full response will be sent over SSE",
|
|
57
|
+
tags: ["messages"],
|
|
58
|
+
request: {
|
|
59
|
+
body: {
|
|
60
|
+
content: { "application/json": { schema: MessageBodySchema } }
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
responses: {
|
|
64
|
+
202: {
|
|
65
|
+
description: "Message accepted for async processing; subscribe to SSE for results",
|
|
66
|
+
content: {
|
|
67
|
+
"application/json": {
|
|
68
|
+
schema: import_zod_openapi.z.object({
|
|
69
|
+
accepted: import_zod_openapi.z.literal(true).describe("Indicates request was accepted"),
|
|
70
|
+
sessionId: import_zod_openapi.z.string().describe("Session ID used for this message")
|
|
71
|
+
}).strict()
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
400: { description: "Validation error" }
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
const messageSyncRoute = (0, import_zod_openapi.createRoute)({
|
|
79
|
+
method: "post",
|
|
80
|
+
path: "/message-sync",
|
|
81
|
+
summary: "Send Message (sync)",
|
|
82
|
+
description: "Sends a message and waits for the full response",
|
|
83
|
+
tags: ["messages"],
|
|
84
|
+
request: {
|
|
85
|
+
body: { content: { "application/json": { schema: MessageBodySchema } } }
|
|
86
|
+
},
|
|
87
|
+
responses: {
|
|
88
|
+
200: {
|
|
89
|
+
description: "Synchronous response",
|
|
90
|
+
content: {
|
|
91
|
+
"application/json": {
|
|
92
|
+
schema: import_zod_openapi.z.object({
|
|
93
|
+
response: import_zod_openapi.z.string().describe("Agent response text"),
|
|
94
|
+
sessionId: import_zod_openapi.z.string().describe("Session ID used for this message"),
|
|
95
|
+
tokenUsage: import_responses.TokenUsageSchema.optional().describe("Token usage statistics"),
|
|
96
|
+
reasoning: import_zod_openapi.z.string().optional().describe("Extended thinking content from reasoning models"),
|
|
97
|
+
model: import_zod_openapi.z.string().optional().describe("Model used for this response"),
|
|
98
|
+
provider: import_zod_openapi.z.enum(import_core.LLM_PROVIDERS).optional().describe("LLM provider"),
|
|
99
|
+
router: import_zod_openapi.z.enum(import_core.LLM_ROUTERS).optional().describe("Router used (e.g., vercel)")
|
|
100
|
+
}).strict()
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
400: { description: "Validation error" }
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
const resetRoute = (0, import_zod_openapi.createRoute)({
|
|
108
|
+
method: "post",
|
|
109
|
+
path: "/reset",
|
|
110
|
+
summary: "Reset Conversation",
|
|
111
|
+
description: "Resets the conversation history for a given session",
|
|
112
|
+
tags: ["messages"],
|
|
113
|
+
request: {
|
|
114
|
+
body: { content: { "application/json": { schema: ResetBodySchema } } }
|
|
115
|
+
},
|
|
116
|
+
responses: {
|
|
117
|
+
200: {
|
|
118
|
+
description: "Reset initiated",
|
|
119
|
+
content: {
|
|
120
|
+
"application/json": {
|
|
121
|
+
schema: import_zod_openapi.z.object({
|
|
122
|
+
status: import_zod_openapi.z.string().describe("Status message indicating reset was initiated"),
|
|
123
|
+
sessionId: import_zod_openapi.z.string().describe("Session ID that was reset")
|
|
124
|
+
}).strict()
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
const messageStreamRoute = (0, import_zod_openapi.createRoute)({
|
|
131
|
+
method: "post",
|
|
132
|
+
path: "/message-stream",
|
|
133
|
+
summary: "Stream message response",
|
|
134
|
+
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.",
|
|
135
|
+
tags: ["messages"],
|
|
136
|
+
request: {
|
|
137
|
+
body: {
|
|
138
|
+
content: { "application/json": { schema: MessageBodySchema } }
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
responses: {
|
|
142
|
+
200: {
|
|
143
|
+
description: "SSE stream of agent events. Standard SSE format with event type and JSON data.",
|
|
144
|
+
headers: {
|
|
145
|
+
"Content-Type": {
|
|
146
|
+
description: "SSE content type",
|
|
147
|
+
schema: { type: "string", example: "text/event-stream" }
|
|
148
|
+
},
|
|
149
|
+
"Cache-Control": {
|
|
150
|
+
description: "Disable caching for stream",
|
|
151
|
+
schema: { type: "string", example: "no-cache" }
|
|
152
|
+
},
|
|
153
|
+
Connection: {
|
|
154
|
+
description: "Keep connection alive for streaming",
|
|
155
|
+
schema: { type: "string", example: "keep-alive" }
|
|
156
|
+
},
|
|
157
|
+
"X-Accel-Buffering": {
|
|
158
|
+
description: "Disable nginx buffering",
|
|
159
|
+
schema: { type: "string", example: "no" }
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
content: {
|
|
163
|
+
"text/event-stream": {
|
|
164
|
+
schema: import_zod_openapi.z.string().describe(
|
|
165
|
+
"Server-Sent Events stream. Events: llm:thinking (start), llm:chunk (text fragments), llm:tool-call (tool execution), llm:tool-result (tool output), llm:response (final), llm:error (errors)"
|
|
166
|
+
)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
400: { description: "Validation error" }
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
return app.openapi(messageRoute, async (ctx) => {
|
|
174
|
+
const agent = getAgent();
|
|
175
|
+
agent.logger.info("Received message via POST /api/message");
|
|
176
|
+
const { message, sessionId, imageData, fileData } = ctx.req.valid("json");
|
|
177
|
+
const imageDataInput = imageData ? { image: imageData.base64, mimeType: imageData.mimeType } : void 0;
|
|
178
|
+
const fileDataInput = fileData ? {
|
|
179
|
+
data: fileData.base64,
|
|
180
|
+
mimeType: fileData.mimeType,
|
|
181
|
+
...fileData.filename && { filename: fileData.filename }
|
|
182
|
+
} : void 0;
|
|
183
|
+
if (imageDataInput) agent.logger.info("Image data included in message.");
|
|
184
|
+
if (fileDataInput) agent.logger.info("File data included in message.");
|
|
185
|
+
agent.logger.info(`Message for session: ${sessionId}`);
|
|
186
|
+
agent.run(message || "", imageDataInput, fileDataInput, sessionId, false).catch((error) => {
|
|
187
|
+
agent.logger.error(
|
|
188
|
+
`Error in async message processing: ${error instanceof Error ? error.message : String(error)}`
|
|
189
|
+
);
|
|
190
|
+
});
|
|
191
|
+
return ctx.json({ accepted: true, sessionId }, 202);
|
|
192
|
+
}).openapi(messageSyncRoute, async (ctx) => {
|
|
193
|
+
const agent = getAgent();
|
|
194
|
+
agent.logger.info("Received message via POST /api/message-sync");
|
|
195
|
+
const { message, sessionId, imageData, fileData } = ctx.req.valid("json");
|
|
196
|
+
const imageDataInput = imageData ? { image: imageData.base64, mimeType: imageData.mimeType } : void 0;
|
|
197
|
+
const fileDataInput = fileData ? {
|
|
198
|
+
data: fileData.base64,
|
|
199
|
+
mimeType: fileData.mimeType,
|
|
200
|
+
...fileData.filename && { filename: fileData.filename }
|
|
201
|
+
} : void 0;
|
|
202
|
+
if (imageDataInput) agent.logger.info("Image data included in message.");
|
|
203
|
+
if (fileDataInput) agent.logger.info("File data included in message.");
|
|
204
|
+
agent.logger.info(`Message for session: ${sessionId}`);
|
|
205
|
+
const result = await agent.generate(message || "", {
|
|
206
|
+
sessionId,
|
|
207
|
+
imageData: imageDataInput,
|
|
208
|
+
fileData: fileDataInput
|
|
209
|
+
});
|
|
210
|
+
const llmConfig = agent.stateManager.getLLMConfig(sessionId);
|
|
211
|
+
return ctx.json({
|
|
212
|
+
response: result.content,
|
|
213
|
+
sessionId: result.sessionId,
|
|
214
|
+
tokenUsage: result.usage,
|
|
215
|
+
reasoning: result.reasoning,
|
|
216
|
+
model: llmConfig.model,
|
|
217
|
+
provider: llmConfig.provider,
|
|
218
|
+
router: "vercel"
|
|
219
|
+
// Hardcoded for now since we only use Vercel AI SDK
|
|
220
|
+
});
|
|
221
|
+
}).openapi(resetRoute, async (ctx) => {
|
|
222
|
+
const agent = getAgent();
|
|
223
|
+
agent.logger.info("Received request via POST /api/reset");
|
|
224
|
+
const { sessionId } = ctx.req.valid("json");
|
|
225
|
+
await agent.resetConversation(sessionId);
|
|
226
|
+
return ctx.json({ status: "reset initiated", sessionId });
|
|
227
|
+
}).openapi(messageStreamRoute, async (ctx) => {
|
|
228
|
+
const agent = getAgent();
|
|
229
|
+
const body = ctx.req.valid("json");
|
|
230
|
+
const { message = "", sessionId, imageData, fileData } = body;
|
|
231
|
+
const imageDataInput = imageData ? { image: imageData.base64, mimeType: imageData.mimeType } : void 0;
|
|
232
|
+
const fileDataInput = fileData ? {
|
|
233
|
+
data: fileData.base64,
|
|
234
|
+
mimeType: fileData.mimeType,
|
|
235
|
+
...fileData.filename && { filename: fileData.filename }
|
|
236
|
+
} : void 0;
|
|
237
|
+
const abortController = new AbortController();
|
|
238
|
+
const { signal } = abortController;
|
|
239
|
+
const iterator = await agent.stream(message, {
|
|
240
|
+
sessionId,
|
|
241
|
+
imageData: imageDataInput,
|
|
242
|
+
fileData: fileDataInput,
|
|
243
|
+
signal
|
|
244
|
+
});
|
|
245
|
+
return (0, import_streaming.streamSSE)(ctx, async (stream) => {
|
|
246
|
+
const pendingApprovalEvents = [];
|
|
247
|
+
if (approvalCoordinator) {
|
|
248
|
+
approvalCoordinator.onRequest(
|
|
249
|
+
(request) => {
|
|
250
|
+
if (request.sessionId === sessionId) {
|
|
251
|
+
pendingApprovalEvents.push({
|
|
252
|
+
event: "approval:request",
|
|
253
|
+
data: request
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
{ signal }
|
|
258
|
+
);
|
|
259
|
+
approvalCoordinator.onResponse(
|
|
260
|
+
(response) => {
|
|
261
|
+
if (response.sessionId === sessionId) {
|
|
262
|
+
pendingApprovalEvents.push({
|
|
263
|
+
event: "approval:response",
|
|
264
|
+
data: response
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
{ signal }
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
try {
|
|
272
|
+
for await (const event of iterator) {
|
|
273
|
+
while (pendingApprovalEvents.length > 0) {
|
|
274
|
+
const approvalEvent = pendingApprovalEvents.shift();
|
|
275
|
+
await stream.writeSSE({
|
|
276
|
+
event: approvalEvent.event,
|
|
277
|
+
data: JSON.stringify(approvalEvent.data)
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
const eventData = event.type === "llm:error" && event.error instanceof Error ? {
|
|
281
|
+
...event,
|
|
282
|
+
error: {
|
|
283
|
+
message: event.error.message,
|
|
284
|
+
name: event.error.name,
|
|
285
|
+
stack: event.error.stack
|
|
286
|
+
}
|
|
287
|
+
} : event;
|
|
288
|
+
await stream.writeSSE({
|
|
289
|
+
event: event.type,
|
|
290
|
+
data: JSON.stringify(eventData)
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
while (pendingApprovalEvents.length > 0) {
|
|
294
|
+
const approvalEvent = pendingApprovalEvents.shift();
|
|
295
|
+
await stream.writeSSE({
|
|
296
|
+
event: approvalEvent.event,
|
|
297
|
+
data: JSON.stringify(approvalEvent.data)
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
} catch (error) {
|
|
301
|
+
await stream.writeSSE({
|
|
302
|
+
event: "llm:error",
|
|
303
|
+
data: JSON.stringify({
|
|
304
|
+
error: {
|
|
305
|
+
message: error instanceof Error ? error.message : String(error)
|
|
306
|
+
},
|
|
307
|
+
recoverable: false,
|
|
308
|
+
sessionId
|
|
309
|
+
})
|
|
310
|
+
});
|
|
311
|
+
} finally {
|
|
312
|
+
abortController.abort();
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
318
|
+
0 && (module.exports = {
|
|
319
|
+
createMessagesRouter
|
|
320
|
+
});
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { OpenAPIHono } from '@hono/zod-openapi';
|
|
2
|
+
import type { DextoAgent } from '@dexto/core';
|
|
3
|
+
import type { ApprovalCoordinator } from '../../approval/approval-coordinator.js';
|
|
4
|
+
export declare function createMessagesRouter(getAgent: () => DextoAgent, approvalCoordinator?: ApprovalCoordinator): OpenAPIHono<import("hono").Env, {
|
|
5
|
+
"/message": {
|
|
6
|
+
$post: {
|
|
7
|
+
input: {
|
|
8
|
+
json: {
|
|
9
|
+
sessionId: string;
|
|
10
|
+
message?: string | undefined;
|
|
11
|
+
imageData?: {
|
|
12
|
+
mimeType: string;
|
|
13
|
+
base64: string;
|
|
14
|
+
} | undefined;
|
|
15
|
+
fileData?: {
|
|
16
|
+
mimeType: string;
|
|
17
|
+
base64: string;
|
|
18
|
+
filename?: string | undefined;
|
|
19
|
+
} | undefined;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
output: {
|
|
23
|
+
sessionId: string;
|
|
24
|
+
accepted: true;
|
|
25
|
+
};
|
|
26
|
+
outputFormat: "json";
|
|
27
|
+
status: 202;
|
|
28
|
+
} | {
|
|
29
|
+
input: {
|
|
30
|
+
json: {
|
|
31
|
+
sessionId: string;
|
|
32
|
+
message?: string | undefined;
|
|
33
|
+
imageData?: {
|
|
34
|
+
mimeType: string;
|
|
35
|
+
base64: string;
|
|
36
|
+
} | undefined;
|
|
37
|
+
fileData?: {
|
|
38
|
+
mimeType: string;
|
|
39
|
+
base64: string;
|
|
40
|
+
filename?: string | undefined;
|
|
41
|
+
} | undefined;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
output: {};
|
|
45
|
+
outputFormat: string;
|
|
46
|
+
status: 400;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
} & {
|
|
50
|
+
"/message-sync": {
|
|
51
|
+
$post: {
|
|
52
|
+
input: {
|
|
53
|
+
json: {
|
|
54
|
+
sessionId: string;
|
|
55
|
+
message?: string | undefined;
|
|
56
|
+
imageData?: {
|
|
57
|
+
mimeType: string;
|
|
58
|
+
base64: string;
|
|
59
|
+
} | undefined;
|
|
60
|
+
fileData?: {
|
|
61
|
+
mimeType: string;
|
|
62
|
+
base64: string;
|
|
63
|
+
filename?: string | undefined;
|
|
64
|
+
} | undefined;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
output: {};
|
|
68
|
+
outputFormat: string;
|
|
69
|
+
status: 400;
|
|
70
|
+
} | {
|
|
71
|
+
input: {
|
|
72
|
+
json: {
|
|
73
|
+
sessionId: string;
|
|
74
|
+
message?: string | undefined;
|
|
75
|
+
imageData?: {
|
|
76
|
+
mimeType: string;
|
|
77
|
+
base64: string;
|
|
78
|
+
} | undefined;
|
|
79
|
+
fileData?: {
|
|
80
|
+
mimeType: string;
|
|
81
|
+
base64: string;
|
|
82
|
+
filename?: string | undefined;
|
|
83
|
+
} | undefined;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
output: {
|
|
87
|
+
sessionId: string;
|
|
88
|
+
response: string;
|
|
89
|
+
provider?: "openai" | "openai-compatible" | "anthropic" | "google" | "groq" | "xai" | "cohere" | undefined;
|
|
90
|
+
model?: string | undefined;
|
|
91
|
+
router?: "vercel" | "in-built" | undefined;
|
|
92
|
+
reasoning?: string | undefined;
|
|
93
|
+
tokenUsage?: {
|
|
94
|
+
inputTokens?: number | undefined;
|
|
95
|
+
outputTokens?: number | undefined;
|
|
96
|
+
reasoningTokens?: number | undefined;
|
|
97
|
+
totalTokens?: number | undefined;
|
|
98
|
+
} | undefined;
|
|
99
|
+
};
|
|
100
|
+
outputFormat: "json";
|
|
101
|
+
status: 200;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
} & {
|
|
105
|
+
"/reset": {
|
|
106
|
+
$post: {
|
|
107
|
+
input: {
|
|
108
|
+
json: {
|
|
109
|
+
sessionId: string;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
output: {
|
|
113
|
+
status: string;
|
|
114
|
+
sessionId: string;
|
|
115
|
+
};
|
|
116
|
+
outputFormat: "json";
|
|
117
|
+
status: 200;
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
} & {
|
|
121
|
+
"/message-stream": {
|
|
122
|
+
$post: {
|
|
123
|
+
input: {
|
|
124
|
+
json: {
|
|
125
|
+
sessionId: string;
|
|
126
|
+
message?: string | undefined;
|
|
127
|
+
imageData?: {
|
|
128
|
+
mimeType: string;
|
|
129
|
+
base64: string;
|
|
130
|
+
} | undefined;
|
|
131
|
+
fileData?: {
|
|
132
|
+
mimeType: string;
|
|
133
|
+
base64: string;
|
|
134
|
+
filename?: string | undefined;
|
|
135
|
+
} | undefined;
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
output: Response;
|
|
139
|
+
outputFormat: "json";
|
|
140
|
+
status: import("hono/utils/http-status").StatusCode;
|
|
141
|
+
} | {
|
|
142
|
+
input: {
|
|
143
|
+
json: {
|
|
144
|
+
sessionId: string;
|
|
145
|
+
message?: string | undefined;
|
|
146
|
+
imageData?: {
|
|
147
|
+
mimeType: string;
|
|
148
|
+
base64: string;
|
|
149
|
+
} | undefined;
|
|
150
|
+
fileData?: {
|
|
151
|
+
mimeType: string;
|
|
152
|
+
base64: string;
|
|
153
|
+
filename?: string | undefined;
|
|
154
|
+
} | undefined;
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
output: {};
|
|
158
|
+
outputFormat: string;
|
|
159
|
+
status: 400;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
}, "/">;
|
|
163
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/hono/routes/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAC;AAEhE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AA4ClF,wBAAgB,oBAAoB,CAChC,QAAQ,EAAE,MAAM,UAAU,EAC1B,mBAAmB,CAAC,EAAE,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAmW5C"}
|