@dexto/server 1.3.0 → 1.5.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 +3 -3
- package/dist/hono/__tests__/test-fixtures.d.ts.map +1 -1
- package/dist/hono/__tests__/test-fixtures.js +3 -3
- package/dist/hono/index.cjs +46 -5
- package/dist/hono/index.d.ts +928 -584
- package/dist/hono/index.d.ts.map +1 -1
- package/dist/hono/index.js +46 -5
- package/dist/hono/middleware/error.d.ts.map +1 -1
- package/dist/hono/routes/a2a-jsonrpc.cjs +3 -3
- package/dist/hono/routes/a2a-jsonrpc.d.ts +4 -1
- package/dist/hono/routes/a2a-jsonrpc.d.ts.map +1 -1
- package/dist/hono/routes/a2a-jsonrpc.js +3 -3
- package/dist/hono/routes/a2a-tasks.cjs +5 -5
- package/dist/hono/routes/a2a-tasks.d.ts +13 -10
- package/dist/hono/routes/a2a-tasks.d.ts.map +1 -1
- package/dist/hono/routes/a2a-tasks.js +5 -5
- package/dist/hono/routes/agents.cjs +30 -42
- package/dist/hono/routes/agents.d.ts +7 -401
- package/dist/hono/routes/agents.d.ts.map +1 -1
- package/dist/hono/routes/agents.js +32 -42
- package/dist/hono/routes/approvals.cjs +53 -2
- package/dist/hono/routes/approvals.d.ts +29 -1
- package/dist/hono/routes/approvals.d.ts.map +1 -1
- package/dist/hono/routes/approvals.js +53 -2
- package/dist/hono/routes/discovery.cjs +67 -0
- package/dist/hono/routes/discovery.d.ts +44 -0
- package/dist/hono/routes/discovery.d.ts.map +1 -0
- package/dist/hono/routes/discovery.js +43 -0
- package/dist/hono/routes/greeting.cjs +2 -2
- package/dist/hono/routes/greeting.d.ts +2 -2
- package/dist/hono/routes/greeting.d.ts.map +1 -1
- package/dist/hono/routes/greeting.js +2 -2
- package/dist/hono/routes/health.d.ts +2 -2
- package/dist/hono/routes/health.d.ts.map +1 -1
- package/dist/hono/routes/key.cjs +110 -0
- package/dist/hono/routes/key.d.ts +48 -0
- package/dist/hono/routes/key.d.ts.map +1 -0
- package/dist/hono/routes/key.js +90 -0
- package/dist/hono/routes/llm.cjs +119 -62
- package/dist/hono/routes/llm.d.ts +242 -42
- package/dist/hono/routes/llm.d.ts.map +1 -1
- package/dist/hono/routes/llm.js +118 -58
- package/dist/hono/routes/mcp.cjs +16 -12
- package/dist/hono/routes/mcp.d.ts +6 -3
- package/dist/hono/routes/mcp.d.ts.map +1 -1
- package/dist/hono/routes/mcp.js +17 -13
- package/dist/hono/routes/memory.cjs +5 -5
- package/dist/hono/routes/memory.d.ts +5 -2
- package/dist/hono/routes/memory.d.ts.map +1 -1
- package/dist/hono/routes/memory.js +5 -5
- package/dist/hono/routes/messages.cjs +58 -66
- package/dist/hono/routes/messages.d.ts +99 -55
- package/dist/hono/routes/messages.d.ts.map +1 -1
- package/dist/hono/routes/messages.js +59 -67
- package/dist/hono/routes/models.cjs +319 -0
- package/dist/hono/routes/models.d.ts +107 -0
- package/dist/hono/routes/models.d.ts.map +1 -0
- package/dist/hono/routes/models.js +305 -0
- package/dist/hono/routes/openrouter.cjs +153 -0
- package/dist/hono/routes/openrouter.d.ts +54 -0
- package/dist/hono/routes/openrouter.d.ts.map +1 -0
- package/dist/hono/routes/openrouter.js +134 -0
- package/dist/hono/routes/prompts.cjs +5 -5
- package/dist/hono/routes/prompts.d.ts +10 -7
- package/dist/hono/routes/prompts.d.ts.map +1 -1
- package/dist/hono/routes/prompts.js +5 -5
- package/dist/hono/routes/queue.cjs +202 -0
- package/dist/hono/routes/queue.d.ts +174 -0
- package/dist/hono/routes/queue.d.ts.map +1 -0
- package/dist/hono/routes/queue.js +178 -0
- package/dist/hono/routes/resources.cjs +3 -3
- package/dist/hono/routes/resources.d.ts +3 -3
- package/dist/hono/routes/resources.d.ts.map +1 -1
- package/dist/hono/routes/resources.js +3 -3
- package/dist/hono/routes/search.cjs +2 -2
- package/dist/hono/routes/search.d.ts +39 -10
- package/dist/hono/routes/search.d.ts.map +1 -1
- package/dist/hono/routes/search.js +2 -2
- package/dist/hono/routes/sessions.cjs +74 -20
- package/dist/hono/routes/sessions.d.ts +25 -4
- package/dist/hono/routes/sessions.d.ts.map +1 -1
- package/dist/hono/routes/sessions.js +74 -20
- package/dist/hono/routes/tools.cjs +126 -0
- package/dist/hono/routes/tools.d.ts +42 -0
- package/dist/hono/routes/tools.d.ts.map +1 -0
- package/dist/hono/routes/tools.js +102 -0
- package/dist/hono/routes/webhooks.cjs +4 -4
- package/dist/hono/routes/webhooks.d.ts +4 -1
- package/dist/hono/routes/webhooks.d.ts.map +1 -1
- package/dist/hono/routes/webhooks.js +4 -4
- package/dist/hono/schemas/responses.cjs +24 -5
- package/dist/hono/schemas/responses.d.ts +838 -120
- package/dist/hono/schemas/responses.d.ts.map +1 -1
- package/dist/hono/schemas/responses.js +24 -10
- package/dist/hono/start-server.cjs +102 -0
- package/dist/hono/start-server.d.ts +61 -0
- package/dist/hono/start-server.d.ts.map +1 -0
- package/dist/hono/start-server.js +78 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/package.json +5 -4
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { OpenAPIHono } from '@hono/zod-openapi';
|
|
2
2
|
import type { DextoAgent } from '@dexto/core';
|
|
3
|
-
|
|
3
|
+
import type { Context } from 'hono';
|
|
4
|
+
type GetAgentFn = (ctx: Context) => DextoAgent | Promise<DextoAgent>;
|
|
5
|
+
export declare function createPromptsRouter(getAgent: GetAgentFn): OpenAPIHono<import("hono").Env, {
|
|
4
6
|
"/prompts": {
|
|
5
7
|
$get: {
|
|
6
8
|
input: {};
|
|
@@ -10,14 +12,14 @@ export declare function createPromptsRouter(getAgent: () => DextoAgent): OpenAPI
|
|
|
10
12
|
source: "config" | "custom" | "mcp";
|
|
11
13
|
description?: string | undefined;
|
|
12
14
|
title?: string | undefined;
|
|
15
|
+
metadata?: {
|
|
16
|
+
[x: string]: import("hono/utils/types").JSONValue;
|
|
17
|
+
} | undefined;
|
|
13
18
|
arguments?: {
|
|
14
19
|
name: string;
|
|
15
20
|
description?: string | undefined;
|
|
16
21
|
required?: boolean | undefined;
|
|
17
22
|
}[] | undefined;
|
|
18
|
-
metadata?: {
|
|
19
|
-
[x: string]: import("hono/utils/types").JSONValue;
|
|
20
|
-
} | undefined;
|
|
21
23
|
}[];
|
|
22
24
|
};
|
|
23
25
|
outputFormat: "json";
|
|
@@ -51,14 +53,14 @@ export declare function createPromptsRouter(getAgent: () => DextoAgent): OpenAPI
|
|
|
51
53
|
source: "config" | "custom" | "mcp";
|
|
52
54
|
description?: string | undefined;
|
|
53
55
|
title?: string | undefined;
|
|
56
|
+
metadata?: {
|
|
57
|
+
[x: string]: import("hono/utils/types").JSONValue;
|
|
58
|
+
} | undefined;
|
|
54
59
|
arguments?: {
|
|
55
60
|
name: string;
|
|
56
61
|
description?: string | undefined;
|
|
57
62
|
required?: boolean | undefined;
|
|
58
63
|
}[] | undefined;
|
|
59
|
-
metadata?: {
|
|
60
|
-
[x: string]: import("hono/utils/types").JSONValue;
|
|
61
|
-
} | undefined;
|
|
62
64
|
};
|
|
63
65
|
};
|
|
64
66
|
outputFormat: "json";
|
|
@@ -147,4 +149,5 @@ export declare function createPromptsRouter(getAgent: () => DextoAgent): OpenAPI
|
|
|
147
149
|
};
|
|
148
150
|
};
|
|
149
151
|
}, "/">;
|
|
152
|
+
export {};
|
|
150
153
|
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../src/hono/routes/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../src/hono/routes/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,KAAK,UAAU,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAmErE,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA6NvD"}
|
|
@@ -139,12 +139,12 @@ function createPromptsRouter(getAgent) {
|
|
|
139
139
|
}
|
|
140
140
|
});
|
|
141
141
|
return app.openapi(listRoute, async (ctx) => {
|
|
142
|
-
const agent = getAgent();
|
|
142
|
+
const agent = await getAgent(ctx);
|
|
143
143
|
const prompts = await agent.listPrompts();
|
|
144
144
|
const list = Object.values(prompts);
|
|
145
145
|
return ctx.json({ prompts: list });
|
|
146
146
|
}).openapi(createCustomRoute, async (ctx) => {
|
|
147
|
-
const agent = getAgent();
|
|
147
|
+
const agent = await getAgent(ctx);
|
|
148
148
|
const payload = ctx.req.valid("json");
|
|
149
149
|
const promptArguments = payload.arguments?.map((arg) => ({
|
|
150
150
|
name: arg.name,
|
|
@@ -168,18 +168,18 @@ function createPromptsRouter(getAgent) {
|
|
|
168
168
|
const prompt = await agent.createCustomPrompt(createPayload);
|
|
169
169
|
return ctx.json({ prompt }, 201);
|
|
170
170
|
}).openapi(deleteCustomRoute, async (ctx) => {
|
|
171
|
-
const agent = getAgent();
|
|
171
|
+
const agent = await getAgent(ctx);
|
|
172
172
|
const { name } = ctx.req.valid("param");
|
|
173
173
|
await agent.deleteCustomPrompt(name);
|
|
174
174
|
return ctx.body(null, 204);
|
|
175
175
|
}).openapi(getPromptRoute, async (ctx) => {
|
|
176
|
-
const agent = getAgent();
|
|
176
|
+
const agent = await getAgent(ctx);
|
|
177
177
|
const { name } = ctx.req.valid("param");
|
|
178
178
|
const definition = await agent.getPromptDefinition(name);
|
|
179
179
|
if (!definition) throw PromptError.notFound(name);
|
|
180
180
|
return ctx.json({ definition });
|
|
181
181
|
}).openapi(resolvePromptRoute, async (ctx) => {
|
|
182
|
-
const agent = getAgent();
|
|
182
|
+
const agent = await getAgent(ctx);
|
|
183
183
|
const { name } = ctx.req.valid("param");
|
|
184
184
|
const { context, args: argsString } = ctx.req.valid("query");
|
|
185
185
|
let parsedArgs;
|
|
@@ -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 = await getAgent(ctx);
|
|
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 = await getAgent(ctx);
|
|
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 = await getAgent(ctx);
|
|
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 = await getAgent(ctx);
|
|
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,174 @@
|
|
|
1
|
+
import { OpenAPIHono } from '@hono/zod-openapi';
|
|
2
|
+
import type { DextoAgent } from '@dexto/core';
|
|
3
|
+
import type { Context } from 'hono';
|
|
4
|
+
type GetAgentFn = (ctx: Context) => DextoAgent | Promise<DextoAgent>;
|
|
5
|
+
export declare function createQueueRouter(getAgent: GetAgentFn): OpenAPIHono<import("hono").Env, {
|
|
6
|
+
"/queue/:sessionId": {
|
|
7
|
+
$get: {
|
|
8
|
+
input: {
|
|
9
|
+
param: {
|
|
10
|
+
sessionId: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
output: {};
|
|
14
|
+
outputFormat: string;
|
|
15
|
+
status: 404;
|
|
16
|
+
} | {
|
|
17
|
+
input: {
|
|
18
|
+
param: {
|
|
19
|
+
sessionId: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
output: {
|
|
23
|
+
messages: {
|
|
24
|
+
content: ({
|
|
25
|
+
type: "text";
|
|
26
|
+
text: string;
|
|
27
|
+
} | {
|
|
28
|
+
type: "image";
|
|
29
|
+
image: string;
|
|
30
|
+
mimeType?: string | undefined;
|
|
31
|
+
} | {
|
|
32
|
+
type: "file";
|
|
33
|
+
mimeType: string;
|
|
34
|
+
data: string;
|
|
35
|
+
filename?: string | undefined;
|
|
36
|
+
} | {
|
|
37
|
+
type: "ui-resource";
|
|
38
|
+
mimeType: string;
|
|
39
|
+
uri: string;
|
|
40
|
+
content?: string | undefined;
|
|
41
|
+
blob?: string | undefined;
|
|
42
|
+
metadata?: {
|
|
43
|
+
title?: string | undefined;
|
|
44
|
+
preferredSize?: {
|
|
45
|
+
width: number;
|
|
46
|
+
height: number;
|
|
47
|
+
} | undefined;
|
|
48
|
+
} | undefined;
|
|
49
|
+
})[];
|
|
50
|
+
id: string;
|
|
51
|
+
queuedAt: number;
|
|
52
|
+
metadata?: {
|
|
53
|
+
[x: string]: import("hono/utils/types").JSONValue;
|
|
54
|
+
} | undefined;
|
|
55
|
+
}[];
|
|
56
|
+
count: number;
|
|
57
|
+
};
|
|
58
|
+
outputFormat: "json";
|
|
59
|
+
status: 200;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
} & {
|
|
63
|
+
"/queue/:sessionId": {
|
|
64
|
+
$post: {
|
|
65
|
+
input: {
|
|
66
|
+
param: {
|
|
67
|
+
sessionId: string;
|
|
68
|
+
};
|
|
69
|
+
} & {
|
|
70
|
+
json: {
|
|
71
|
+
content: string | ({
|
|
72
|
+
type: "text";
|
|
73
|
+
text: string;
|
|
74
|
+
} | {
|
|
75
|
+
type: "image";
|
|
76
|
+
image: string;
|
|
77
|
+
mimeType?: string | undefined;
|
|
78
|
+
} | {
|
|
79
|
+
type: "file";
|
|
80
|
+
mimeType: string;
|
|
81
|
+
data: string;
|
|
82
|
+
filename?: string | undefined;
|
|
83
|
+
})[];
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
output: {};
|
|
87
|
+
outputFormat: string;
|
|
88
|
+
status: 404;
|
|
89
|
+
} | {
|
|
90
|
+
input: {
|
|
91
|
+
param: {
|
|
92
|
+
sessionId: string;
|
|
93
|
+
};
|
|
94
|
+
} & {
|
|
95
|
+
json: {
|
|
96
|
+
content: string | ({
|
|
97
|
+
type: "text";
|
|
98
|
+
text: string;
|
|
99
|
+
} | {
|
|
100
|
+
type: "image";
|
|
101
|
+
image: string;
|
|
102
|
+
mimeType?: string | undefined;
|
|
103
|
+
} | {
|
|
104
|
+
type: "file";
|
|
105
|
+
mimeType: string;
|
|
106
|
+
data: string;
|
|
107
|
+
filename?: string | undefined;
|
|
108
|
+
})[];
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
output: {
|
|
112
|
+
id: string;
|
|
113
|
+
queued: true;
|
|
114
|
+
position: number;
|
|
115
|
+
};
|
|
116
|
+
outputFormat: "json";
|
|
117
|
+
status: 201;
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
} & {
|
|
121
|
+
"/queue/:sessionId/:messageId": {
|
|
122
|
+
$delete: {
|
|
123
|
+
input: {
|
|
124
|
+
param: {
|
|
125
|
+
sessionId: string;
|
|
126
|
+
messageId: string;
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
output: {};
|
|
130
|
+
outputFormat: string;
|
|
131
|
+
status: 404;
|
|
132
|
+
} | {
|
|
133
|
+
input: {
|
|
134
|
+
param: {
|
|
135
|
+
sessionId: string;
|
|
136
|
+
messageId: string;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
output: {
|
|
140
|
+
id: string;
|
|
141
|
+
removed: true;
|
|
142
|
+
};
|
|
143
|
+
outputFormat: "json";
|
|
144
|
+
status: 200;
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
} & {
|
|
148
|
+
"/queue/:sessionId": {
|
|
149
|
+
$delete: {
|
|
150
|
+
input: {
|
|
151
|
+
param: {
|
|
152
|
+
sessionId: string;
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
output: {};
|
|
156
|
+
outputFormat: string;
|
|
157
|
+
status: 404;
|
|
158
|
+
} | {
|
|
159
|
+
input: {
|
|
160
|
+
param: {
|
|
161
|
+
sessionId: string;
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
output: {
|
|
165
|
+
count: number;
|
|
166
|
+
cleared: true;
|
|
167
|
+
};
|
|
168
|
+
outputFormat: "json";
|
|
169
|
+
status: 200;
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
}, "/">;
|
|
173
|
+
export {};
|
|
174
|
+
//# 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;AAE3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,KAAK,UAAU,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAqDrE,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAoLrD"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
|
2
|
+
import { ContentPartSchema } from "../schemas/responses.js";
|
|
3
|
+
const QueuedMessageSchema = z.object({
|
|
4
|
+
id: z.string().describe("Unique identifier for the queued message"),
|
|
5
|
+
content: z.array(ContentPartSchema).describe("Message content parts"),
|
|
6
|
+
queuedAt: z.number().describe("Unix timestamp when message was queued"),
|
|
7
|
+
metadata: z.record(z.unknown()).optional().describe("Optional metadata")
|
|
8
|
+
}).strict().describe("A message waiting in the queue");
|
|
9
|
+
const TextPartSchema = z.object({
|
|
10
|
+
type: z.literal("text").describe("Content type identifier"),
|
|
11
|
+
text: z.string().describe("Text content")
|
|
12
|
+
}).describe("Text content part");
|
|
13
|
+
const ImagePartSchema = z.object({
|
|
14
|
+
type: z.literal("image").describe("Content type identifier"),
|
|
15
|
+
image: z.string().describe("Base64-encoded image data or URL"),
|
|
16
|
+
mimeType: z.string().optional().describe("MIME type (e.g., image/png)")
|
|
17
|
+
}).describe("Image content part");
|
|
18
|
+
const FilePartSchema = z.object({
|
|
19
|
+
type: z.literal("file").describe("Content type identifier"),
|
|
20
|
+
data: z.string().describe("Base64-encoded file data or URL"),
|
|
21
|
+
mimeType: z.string().describe("MIME type (e.g., application/pdf)"),
|
|
22
|
+
filename: z.string().optional().describe("Optional filename")
|
|
23
|
+
}).describe("File content part");
|
|
24
|
+
const QueueContentPartSchema = z.discriminatedUnion("type", [TextPartSchema, ImagePartSchema, FilePartSchema]).describe("Content part - text, image, or file");
|
|
25
|
+
const QueueMessageBodySchema = z.object({
|
|
26
|
+
content: z.union([z.string(), z.array(QueueContentPartSchema)]).describe("Message content - string for text, or ContentPart[] for multimodal")
|
|
27
|
+
}).describe("Request body for queueing a message");
|
|
28
|
+
function createQueueRouter(getAgent) {
|
|
29
|
+
const app = new OpenAPIHono();
|
|
30
|
+
const getQueueRoute = createRoute({
|
|
31
|
+
method: "get",
|
|
32
|
+
path: "/queue/{sessionId}",
|
|
33
|
+
summary: "Get queued messages",
|
|
34
|
+
description: "Returns all messages waiting in the queue for a session",
|
|
35
|
+
tags: ["queue"],
|
|
36
|
+
request: {
|
|
37
|
+
params: z.object({
|
|
38
|
+
sessionId: z.string().min(1).describe("Session ID")
|
|
39
|
+
})
|
|
40
|
+
},
|
|
41
|
+
responses: {
|
|
42
|
+
200: {
|
|
43
|
+
description: "List of queued messages",
|
|
44
|
+
content: {
|
|
45
|
+
"application/json": {
|
|
46
|
+
schema: z.object({
|
|
47
|
+
messages: z.array(QueuedMessageSchema).describe("Queued messages"),
|
|
48
|
+
count: z.number().describe("Number of messages in queue")
|
|
49
|
+
}).strict()
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
404: { description: "Session not found" }
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
const queueMessageRoute = createRoute({
|
|
57
|
+
method: "post",
|
|
58
|
+
path: "/queue/{sessionId}",
|
|
59
|
+
summary: "Queue a message",
|
|
60
|
+
description: "Adds a message to the queue for processing when the session is no longer busy",
|
|
61
|
+
tags: ["queue"],
|
|
62
|
+
request: {
|
|
63
|
+
params: z.object({
|
|
64
|
+
sessionId: z.string().min(1).describe("Session ID")
|
|
65
|
+
}),
|
|
66
|
+
body: {
|
|
67
|
+
content: { "application/json": { schema: QueueMessageBodySchema } }
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
responses: {
|
|
71
|
+
201: {
|
|
72
|
+
description: "Message queued successfully",
|
|
73
|
+
content: {
|
|
74
|
+
"application/json": {
|
|
75
|
+
schema: z.object({
|
|
76
|
+
queued: z.literal(true).describe("Indicates message was queued"),
|
|
77
|
+
id: z.string().describe("ID of the queued message"),
|
|
78
|
+
position: z.number().describe("Position in the queue (1-based)")
|
|
79
|
+
}).strict()
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
404: { description: "Session not found" }
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
const removeQueuedMessageRoute = createRoute({
|
|
87
|
+
method: "delete",
|
|
88
|
+
path: "/queue/{sessionId}/{messageId}",
|
|
89
|
+
summary: "Remove queued message",
|
|
90
|
+
description: "Removes a specific message from the queue",
|
|
91
|
+
tags: ["queue"],
|
|
92
|
+
request: {
|
|
93
|
+
params: z.object({
|
|
94
|
+
sessionId: z.string().min(1).describe("Session ID"),
|
|
95
|
+
messageId: z.string().min(1).describe("ID of the queued message to remove")
|
|
96
|
+
})
|
|
97
|
+
},
|
|
98
|
+
responses: {
|
|
99
|
+
200: {
|
|
100
|
+
description: "Message removed successfully",
|
|
101
|
+
content: {
|
|
102
|
+
"application/json": {
|
|
103
|
+
schema: z.object({
|
|
104
|
+
removed: z.literal(true).describe("Indicates message was removed"),
|
|
105
|
+
id: z.string().describe("ID of the removed message")
|
|
106
|
+
}).strict()
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
404: { description: "Session or message not found" }
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
const clearQueueRoute = createRoute({
|
|
114
|
+
method: "delete",
|
|
115
|
+
path: "/queue/{sessionId}",
|
|
116
|
+
summary: "Clear message queue",
|
|
117
|
+
description: "Removes all messages from the queue for a session",
|
|
118
|
+
tags: ["queue"],
|
|
119
|
+
request: {
|
|
120
|
+
params: z.object({
|
|
121
|
+
sessionId: z.string().min(1).describe("Session ID")
|
|
122
|
+
})
|
|
123
|
+
},
|
|
124
|
+
responses: {
|
|
125
|
+
200: {
|
|
126
|
+
description: "Queue cleared successfully",
|
|
127
|
+
content: {
|
|
128
|
+
"application/json": {
|
|
129
|
+
schema: z.object({
|
|
130
|
+
cleared: z.literal(true).describe("Indicates queue was cleared"),
|
|
131
|
+
count: z.number().describe("Number of messages that were removed")
|
|
132
|
+
}).strict()
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
404: { description: "Session not found" }
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
return app.openapi(getQueueRoute, async (ctx) => {
|
|
140
|
+
const agent = await getAgent(ctx);
|
|
141
|
+
const { sessionId } = ctx.req.valid("param");
|
|
142
|
+
const messages = await agent.getQueuedMessages(sessionId);
|
|
143
|
+
return ctx.json({
|
|
144
|
+
messages,
|
|
145
|
+
count: messages.length
|
|
146
|
+
});
|
|
147
|
+
}).openapi(queueMessageRoute, async (ctx) => {
|
|
148
|
+
const agent = await getAgent(ctx);
|
|
149
|
+
const { sessionId } = ctx.req.valid("param");
|
|
150
|
+
const { content: rawContent } = ctx.req.valid("json");
|
|
151
|
+
const content = typeof rawContent === "string" ? [{ type: "text", text: rawContent }] : rawContent;
|
|
152
|
+
const result = await agent.queueMessage(sessionId, { content });
|
|
153
|
+
return ctx.json(
|
|
154
|
+
{
|
|
155
|
+
queued: result.queued,
|
|
156
|
+
id: result.id,
|
|
157
|
+
position: result.position
|
|
158
|
+
},
|
|
159
|
+
201
|
|
160
|
+
);
|
|
161
|
+
}).openapi(removeQueuedMessageRoute, async (ctx) => {
|
|
162
|
+
const agent = await getAgent(ctx);
|
|
163
|
+
const { sessionId, messageId } = ctx.req.valid("param");
|
|
164
|
+
const removed = await agent.removeQueuedMessage(sessionId, messageId);
|
|
165
|
+
if (!removed) {
|
|
166
|
+
return ctx.json({ error: "Message not found in queue" }, 404);
|
|
167
|
+
}
|
|
168
|
+
return ctx.json({ removed: true, id: messageId });
|
|
169
|
+
}).openapi(clearQueueRoute, async (ctx) => {
|
|
170
|
+
const agent = await getAgent(ctx);
|
|
171
|
+
const { sessionId } = ctx.req.valid("param");
|
|
172
|
+
const count = await agent.clearMessageQueue(sessionId);
|
|
173
|
+
return ctx.json({ cleared: true, count });
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
export {
|
|
177
|
+
createQueueRouter
|
|
178
|
+
};
|
|
@@ -89,16 +89,16 @@ function createResourcesRouter(getAgent) {
|
|
|
89
89
|
}
|
|
90
90
|
});
|
|
91
91
|
return app.openapi(listRoute, async (ctx) => {
|
|
92
|
-
const agent = getAgent();
|
|
92
|
+
const agent = await getAgent(ctx);
|
|
93
93
|
const resources = await agent.listResources();
|
|
94
94
|
return ctx.json({ ok: true, resources: Object.values(resources) });
|
|
95
95
|
}).openapi(getContentRoute, async (ctx) => {
|
|
96
|
-
const agent = getAgent();
|
|
96
|
+
const agent = await getAgent(ctx);
|
|
97
97
|
const { resourceId } = ctx.req.valid("param");
|
|
98
98
|
const content = await agent.readResource(resourceId);
|
|
99
99
|
return ctx.json({ ok: true, content });
|
|
100
100
|
}).openapi(headRoute, async (ctx) => {
|
|
101
|
-
const agent = getAgent();
|
|
101
|
+
const agent = await getAgent(ctx);
|
|
102
102
|
const { resourceId } = ctx.req.valid("param");
|
|
103
103
|
const exists = await agent.hasResource(resourceId);
|
|
104
104
|
return ctx.body(null, exists ? 200 : 404);
|