@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,228 @@
|
|
|
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 webhooks_exports = {};
|
|
20
|
+
__export(webhooks_exports, {
|
|
21
|
+
createWebhooksRouter: () => createWebhooksRouter
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(webhooks_exports);
|
|
24
|
+
var import_zod_openapi = require("@hono/zod-openapi");
|
|
25
|
+
const WebhookResponseSchema = import_zod_openapi.z.object({
|
|
26
|
+
id: import_zod_openapi.z.string().describe("Unique webhook identifier"),
|
|
27
|
+
url: import_zod_openapi.z.string().url().describe("Webhook URL"),
|
|
28
|
+
description: import_zod_openapi.z.string().optional().describe("Webhook description"),
|
|
29
|
+
createdAt: import_zod_openapi.z.union([import_zod_openapi.z.date(), import_zod_openapi.z.number()]).describe("Creation timestamp (Date or Unix ms)")
|
|
30
|
+
}).strict().describe("Webhook response object");
|
|
31
|
+
const WebhookTestResultSchema = import_zod_openapi.z.object({
|
|
32
|
+
success: import_zod_openapi.z.boolean().describe("Whether the webhook test succeeded"),
|
|
33
|
+
statusCode: import_zod_openapi.z.number().optional().describe("HTTP status code from webhook"),
|
|
34
|
+
responseTime: import_zod_openapi.z.number().optional().describe("Response time in milliseconds"),
|
|
35
|
+
error: import_zod_openapi.z.string().optional().describe("Error message if test failed")
|
|
36
|
+
}).strict().describe("Webhook test result");
|
|
37
|
+
const WebhookBodySchema = import_zod_openapi.z.object({
|
|
38
|
+
url: import_zod_openapi.z.string().url("Invalid URL format").describe("The URL to send webhook events to (must be a valid HTTP/HTTPS URL)"),
|
|
39
|
+
secret: import_zod_openapi.z.string().optional().describe("A secret key for HMAC signature verification"),
|
|
40
|
+
description: import_zod_openapi.z.string().optional().describe("A description of the webhook for reference")
|
|
41
|
+
}).describe("Request body for registering a webhook");
|
|
42
|
+
function createWebhooksRouter(getAgent, webhookSubscriber) {
|
|
43
|
+
const app = new import_zod_openapi.OpenAPIHono();
|
|
44
|
+
const registerRoute = (0, import_zod_openapi.createRoute)({
|
|
45
|
+
method: "post",
|
|
46
|
+
path: "/webhooks",
|
|
47
|
+
summary: "Register Webhook",
|
|
48
|
+
description: "Registers a new webhook endpoint to receive agent events",
|
|
49
|
+
tags: ["webhooks"],
|
|
50
|
+
request: { body: { content: { "application/json": { schema: WebhookBodySchema } } } },
|
|
51
|
+
responses: {
|
|
52
|
+
201: {
|
|
53
|
+
description: "Webhook registered",
|
|
54
|
+
content: {
|
|
55
|
+
"application/json": {
|
|
56
|
+
schema: import_zod_openapi.z.object({
|
|
57
|
+
webhook: WebhookResponseSchema.describe(
|
|
58
|
+
"Registered webhook details"
|
|
59
|
+
)
|
|
60
|
+
}).strict()
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
const listRoute = (0, import_zod_openapi.createRoute)({
|
|
67
|
+
method: "get",
|
|
68
|
+
path: "/webhooks",
|
|
69
|
+
summary: "List Webhooks",
|
|
70
|
+
description: "Retrieves a list of all registered webhooks",
|
|
71
|
+
tags: ["webhooks"],
|
|
72
|
+
responses: {
|
|
73
|
+
200: {
|
|
74
|
+
description: "List webhooks",
|
|
75
|
+
content: {
|
|
76
|
+
"application/json": {
|
|
77
|
+
schema: import_zod_openapi.z.object({
|
|
78
|
+
webhooks: import_zod_openapi.z.array(WebhookResponseSchema).describe("Array of registered webhooks")
|
|
79
|
+
}).strict()
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
const getRoute = (0, import_zod_openapi.createRoute)({
|
|
86
|
+
method: "get",
|
|
87
|
+
path: "/webhooks/{webhookId}",
|
|
88
|
+
summary: "Get Webhook Details",
|
|
89
|
+
description: "Fetches details for a specific webhook",
|
|
90
|
+
tags: ["webhooks"],
|
|
91
|
+
request: { params: import_zod_openapi.z.object({ webhookId: import_zod_openapi.z.string().describe("The webhook identifier") }) },
|
|
92
|
+
responses: {
|
|
93
|
+
200: {
|
|
94
|
+
description: "Webhook",
|
|
95
|
+
content: {
|
|
96
|
+
"application/json": {
|
|
97
|
+
schema: import_zod_openapi.z.object({
|
|
98
|
+
webhook: WebhookResponseSchema.describe("Webhook details")
|
|
99
|
+
}).strict()
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
404: { description: "Not found" }
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
const deleteRoute = (0, import_zod_openapi.createRoute)({
|
|
107
|
+
method: "delete",
|
|
108
|
+
path: "/webhooks/{webhookId}",
|
|
109
|
+
summary: "Delete Webhook",
|
|
110
|
+
description: "Permanently removes a webhook endpoint. This action cannot be undone",
|
|
111
|
+
tags: ["webhooks"],
|
|
112
|
+
request: { params: import_zod_openapi.z.object({ webhookId: import_zod_openapi.z.string().describe("The webhook identifier") }) },
|
|
113
|
+
responses: {
|
|
114
|
+
200: {
|
|
115
|
+
description: "Removed",
|
|
116
|
+
content: {
|
|
117
|
+
"application/json": {
|
|
118
|
+
schema: import_zod_openapi.z.object({
|
|
119
|
+
status: import_zod_openapi.z.literal("removed").describe("Operation status indicating successful removal"),
|
|
120
|
+
webhookId: import_zod_openapi.z.string().describe("ID of the removed webhook")
|
|
121
|
+
}).strict()
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
404: { description: "Not found" }
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
const testRoute = (0, import_zod_openapi.createRoute)({
|
|
129
|
+
method: "post",
|
|
130
|
+
path: "/webhooks/{webhookId}/test",
|
|
131
|
+
summary: "Test Webhook",
|
|
132
|
+
description: "Sends a sample event to test webhook connectivity and configuration",
|
|
133
|
+
tags: ["webhooks"],
|
|
134
|
+
request: { params: import_zod_openapi.z.object({ webhookId: import_zod_openapi.z.string().describe("The webhook identifier") }) },
|
|
135
|
+
responses: {
|
|
136
|
+
200: {
|
|
137
|
+
description: "Test result",
|
|
138
|
+
content: {
|
|
139
|
+
"application/json": {
|
|
140
|
+
schema: import_zod_openapi.z.object({
|
|
141
|
+
test: import_zod_openapi.z.literal("completed").describe("Test status indicating completion"),
|
|
142
|
+
result: WebhookTestResultSchema.describe("Test execution results")
|
|
143
|
+
}).strict()
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
404: { description: "Not found" }
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
return app.openapi(registerRoute, async (ctx) => {
|
|
151
|
+
const agent = getAgent();
|
|
152
|
+
const { url, secret, description } = ctx.req.valid("json");
|
|
153
|
+
const webhookId = `wh_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
|
154
|
+
const webhook = {
|
|
155
|
+
id: webhookId,
|
|
156
|
+
url,
|
|
157
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
158
|
+
...secret && { secret },
|
|
159
|
+
...description && { description }
|
|
160
|
+
};
|
|
161
|
+
webhookSubscriber.addWebhook(webhook);
|
|
162
|
+
agent.logger.info(`Webhook registered: ${webhookId} -> ${url}`);
|
|
163
|
+
return ctx.json(
|
|
164
|
+
{
|
|
165
|
+
webhook: {
|
|
166
|
+
id: webhook.id,
|
|
167
|
+
url: webhook.url,
|
|
168
|
+
description: webhook.description,
|
|
169
|
+
createdAt: webhook.createdAt
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
201
|
|
173
|
+
);
|
|
174
|
+
}).openapi(listRoute, async (ctx) => {
|
|
175
|
+
const webhooks = webhookSubscriber.getWebhooks().map((webhook) => ({
|
|
176
|
+
id: webhook.id,
|
|
177
|
+
url: webhook.url,
|
|
178
|
+
description: webhook.description,
|
|
179
|
+
createdAt: webhook.createdAt
|
|
180
|
+
}));
|
|
181
|
+
return ctx.json({ webhooks });
|
|
182
|
+
}).openapi(getRoute, (ctx) => {
|
|
183
|
+
const { webhookId } = ctx.req.valid("param");
|
|
184
|
+
const webhook = webhookSubscriber.getWebhook(webhookId);
|
|
185
|
+
if (!webhook) {
|
|
186
|
+
return ctx.json({ error: "Webhook not found" }, 404);
|
|
187
|
+
}
|
|
188
|
+
return ctx.json({
|
|
189
|
+
webhook: {
|
|
190
|
+
id: webhook.id,
|
|
191
|
+
url: webhook.url,
|
|
192
|
+
description: webhook.description,
|
|
193
|
+
createdAt: webhook.createdAt
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}).openapi(deleteRoute, (ctx) => {
|
|
197
|
+
const agent = getAgent();
|
|
198
|
+
const { webhookId } = ctx.req.valid("param");
|
|
199
|
+
const removed = webhookSubscriber.removeWebhook(webhookId);
|
|
200
|
+
if (!removed) {
|
|
201
|
+
return ctx.json({ error: "Webhook not found" }, 404);
|
|
202
|
+
}
|
|
203
|
+
agent.logger.info(`Webhook removed: ${webhookId}`);
|
|
204
|
+
return ctx.json({ status: "removed", webhookId });
|
|
205
|
+
}).openapi(testRoute, async (ctx) => {
|
|
206
|
+
const agent = getAgent();
|
|
207
|
+
const { webhookId } = ctx.req.valid("param");
|
|
208
|
+
const webhook = webhookSubscriber.getWebhook(webhookId);
|
|
209
|
+
if (!webhook) {
|
|
210
|
+
return ctx.json({ error: "Webhook not found" }, 404);
|
|
211
|
+
}
|
|
212
|
+
agent.logger.info(`Testing webhook: ${webhookId}`);
|
|
213
|
+
const result = await webhookSubscriber.testWebhook(webhookId);
|
|
214
|
+
return ctx.json({
|
|
215
|
+
test: "completed",
|
|
216
|
+
result: {
|
|
217
|
+
success: result.success,
|
|
218
|
+
statusCode: result.statusCode,
|
|
219
|
+
responseTime: result.responseTime,
|
|
220
|
+
error: result.error
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
226
|
+
0 && (module.exports = {
|
|
227
|
+
createWebhooksRouter
|
|
228
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { OpenAPIHono } from '@hono/zod-openapi';
|
|
2
|
+
import type { DextoAgent } from '@dexto/core';
|
|
3
|
+
import { WebhookEventSubscriber } from '../../events/webhook-subscriber.js';
|
|
4
|
+
export declare function createWebhooksRouter(getAgent: () => DextoAgent, webhookSubscriber: WebhookEventSubscriber): OpenAPIHono<import("hono").Env, {
|
|
5
|
+
"/webhooks": {
|
|
6
|
+
$post: {
|
|
7
|
+
input: {
|
|
8
|
+
json: {
|
|
9
|
+
url: string;
|
|
10
|
+
description?: string | undefined;
|
|
11
|
+
secret?: string | undefined;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
output: {
|
|
15
|
+
webhook: {
|
|
16
|
+
id: string;
|
|
17
|
+
createdAt: string | number;
|
|
18
|
+
url: string;
|
|
19
|
+
description?: string | undefined;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
outputFormat: "json";
|
|
23
|
+
status: 201;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
} & {
|
|
27
|
+
"/webhooks": {
|
|
28
|
+
$get: {
|
|
29
|
+
input: {};
|
|
30
|
+
output: {
|
|
31
|
+
webhooks: {
|
|
32
|
+
id: string;
|
|
33
|
+
createdAt: string | number;
|
|
34
|
+
url: string;
|
|
35
|
+
description?: string | undefined;
|
|
36
|
+
}[];
|
|
37
|
+
};
|
|
38
|
+
outputFormat: "json";
|
|
39
|
+
status: 200;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
} & {
|
|
43
|
+
"/webhooks/:webhookId": {
|
|
44
|
+
$get: {
|
|
45
|
+
input: {
|
|
46
|
+
param: {
|
|
47
|
+
webhookId: string;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
output: {};
|
|
51
|
+
outputFormat: string;
|
|
52
|
+
status: 404;
|
|
53
|
+
} | {
|
|
54
|
+
input: {
|
|
55
|
+
param: {
|
|
56
|
+
webhookId: string;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
output: {
|
|
60
|
+
webhook: {
|
|
61
|
+
id: string;
|
|
62
|
+
createdAt: string | number;
|
|
63
|
+
url: string;
|
|
64
|
+
description?: string | undefined;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
outputFormat: "json";
|
|
68
|
+
status: 200;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
} & {
|
|
72
|
+
"/webhooks/:webhookId": {
|
|
73
|
+
$delete: {
|
|
74
|
+
input: {
|
|
75
|
+
param: {
|
|
76
|
+
webhookId: string;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
output: {};
|
|
80
|
+
outputFormat: string;
|
|
81
|
+
status: 404;
|
|
82
|
+
} | {
|
|
83
|
+
input: {
|
|
84
|
+
param: {
|
|
85
|
+
webhookId: string;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
output: {
|
|
89
|
+
status: "removed";
|
|
90
|
+
webhookId: string;
|
|
91
|
+
};
|
|
92
|
+
outputFormat: "json";
|
|
93
|
+
status: 200;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
} & {
|
|
97
|
+
"/webhooks/:webhookId/test": {
|
|
98
|
+
$post: {
|
|
99
|
+
input: {
|
|
100
|
+
param: {
|
|
101
|
+
webhookId: string;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
output: {};
|
|
105
|
+
outputFormat: string;
|
|
106
|
+
status: 404;
|
|
107
|
+
} | {
|
|
108
|
+
input: {
|
|
109
|
+
param: {
|
|
110
|
+
webhookId: string;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
output: {
|
|
114
|
+
result: {
|
|
115
|
+
success: boolean;
|
|
116
|
+
error?: string | undefined;
|
|
117
|
+
responseTime?: number | undefined;
|
|
118
|
+
statusCode?: number | undefined;
|
|
119
|
+
};
|
|
120
|
+
test: "completed";
|
|
121
|
+
};
|
|
122
|
+
outputFormat: "json";
|
|
123
|
+
status: 200;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
}, "/">;
|
|
127
|
+
//# sourceMappingURL=webhooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../../../src/hono/routes/webhooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAmC5E,wBAAgB,oBAAoB,CAChC,QAAQ,EAAE,MAAM,UAAU,EAC1B,iBAAiB,EAAE,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA0N5C"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
|
2
|
+
const WebhookResponseSchema = z.object({
|
|
3
|
+
id: z.string().describe("Unique webhook identifier"),
|
|
4
|
+
url: z.string().url().describe("Webhook URL"),
|
|
5
|
+
description: z.string().optional().describe("Webhook description"),
|
|
6
|
+
createdAt: z.union([z.date(), z.number()]).describe("Creation timestamp (Date or Unix ms)")
|
|
7
|
+
}).strict().describe("Webhook response object");
|
|
8
|
+
const WebhookTestResultSchema = z.object({
|
|
9
|
+
success: z.boolean().describe("Whether the webhook test succeeded"),
|
|
10
|
+
statusCode: z.number().optional().describe("HTTP status code from webhook"),
|
|
11
|
+
responseTime: z.number().optional().describe("Response time in milliseconds"),
|
|
12
|
+
error: z.string().optional().describe("Error message if test failed")
|
|
13
|
+
}).strict().describe("Webhook test result");
|
|
14
|
+
const WebhookBodySchema = z.object({
|
|
15
|
+
url: z.string().url("Invalid URL format").describe("The URL to send webhook events to (must be a valid HTTP/HTTPS URL)"),
|
|
16
|
+
secret: z.string().optional().describe("A secret key for HMAC signature verification"),
|
|
17
|
+
description: z.string().optional().describe("A description of the webhook for reference")
|
|
18
|
+
}).describe("Request body for registering a webhook");
|
|
19
|
+
function createWebhooksRouter(getAgent, webhookSubscriber) {
|
|
20
|
+
const app = new OpenAPIHono();
|
|
21
|
+
const registerRoute = createRoute({
|
|
22
|
+
method: "post",
|
|
23
|
+
path: "/webhooks",
|
|
24
|
+
summary: "Register Webhook",
|
|
25
|
+
description: "Registers a new webhook endpoint to receive agent events",
|
|
26
|
+
tags: ["webhooks"],
|
|
27
|
+
request: { body: { content: { "application/json": { schema: WebhookBodySchema } } } },
|
|
28
|
+
responses: {
|
|
29
|
+
201: {
|
|
30
|
+
description: "Webhook registered",
|
|
31
|
+
content: {
|
|
32
|
+
"application/json": {
|
|
33
|
+
schema: z.object({
|
|
34
|
+
webhook: WebhookResponseSchema.describe(
|
|
35
|
+
"Registered webhook details"
|
|
36
|
+
)
|
|
37
|
+
}).strict()
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const listRoute = createRoute({
|
|
44
|
+
method: "get",
|
|
45
|
+
path: "/webhooks",
|
|
46
|
+
summary: "List Webhooks",
|
|
47
|
+
description: "Retrieves a list of all registered webhooks",
|
|
48
|
+
tags: ["webhooks"],
|
|
49
|
+
responses: {
|
|
50
|
+
200: {
|
|
51
|
+
description: "List webhooks",
|
|
52
|
+
content: {
|
|
53
|
+
"application/json": {
|
|
54
|
+
schema: z.object({
|
|
55
|
+
webhooks: z.array(WebhookResponseSchema).describe("Array of registered webhooks")
|
|
56
|
+
}).strict()
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const getRoute = createRoute({
|
|
63
|
+
method: "get",
|
|
64
|
+
path: "/webhooks/{webhookId}",
|
|
65
|
+
summary: "Get Webhook Details",
|
|
66
|
+
description: "Fetches details for a specific webhook",
|
|
67
|
+
tags: ["webhooks"],
|
|
68
|
+
request: { params: z.object({ webhookId: z.string().describe("The webhook identifier") }) },
|
|
69
|
+
responses: {
|
|
70
|
+
200: {
|
|
71
|
+
description: "Webhook",
|
|
72
|
+
content: {
|
|
73
|
+
"application/json": {
|
|
74
|
+
schema: z.object({
|
|
75
|
+
webhook: WebhookResponseSchema.describe("Webhook details")
|
|
76
|
+
}).strict()
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
404: { description: "Not found" }
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
const deleteRoute = createRoute({
|
|
84
|
+
method: "delete",
|
|
85
|
+
path: "/webhooks/{webhookId}",
|
|
86
|
+
summary: "Delete Webhook",
|
|
87
|
+
description: "Permanently removes a webhook endpoint. This action cannot be undone",
|
|
88
|
+
tags: ["webhooks"],
|
|
89
|
+
request: { params: z.object({ webhookId: z.string().describe("The webhook identifier") }) },
|
|
90
|
+
responses: {
|
|
91
|
+
200: {
|
|
92
|
+
description: "Removed",
|
|
93
|
+
content: {
|
|
94
|
+
"application/json": {
|
|
95
|
+
schema: z.object({
|
|
96
|
+
status: z.literal("removed").describe("Operation status indicating successful removal"),
|
|
97
|
+
webhookId: z.string().describe("ID of the removed webhook")
|
|
98
|
+
}).strict()
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
404: { description: "Not found" }
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
const testRoute = createRoute({
|
|
106
|
+
method: "post",
|
|
107
|
+
path: "/webhooks/{webhookId}/test",
|
|
108
|
+
summary: "Test Webhook",
|
|
109
|
+
description: "Sends a sample event to test webhook connectivity and configuration",
|
|
110
|
+
tags: ["webhooks"],
|
|
111
|
+
request: { params: z.object({ webhookId: z.string().describe("The webhook identifier") }) },
|
|
112
|
+
responses: {
|
|
113
|
+
200: {
|
|
114
|
+
description: "Test result",
|
|
115
|
+
content: {
|
|
116
|
+
"application/json": {
|
|
117
|
+
schema: z.object({
|
|
118
|
+
test: z.literal("completed").describe("Test status indicating completion"),
|
|
119
|
+
result: WebhookTestResultSchema.describe("Test execution results")
|
|
120
|
+
}).strict()
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
404: { description: "Not found" }
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
return app.openapi(registerRoute, async (ctx) => {
|
|
128
|
+
const agent = getAgent();
|
|
129
|
+
const { url, secret, description } = ctx.req.valid("json");
|
|
130
|
+
const webhookId = `wh_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
|
131
|
+
const webhook = {
|
|
132
|
+
id: webhookId,
|
|
133
|
+
url,
|
|
134
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
135
|
+
...secret && { secret },
|
|
136
|
+
...description && { description }
|
|
137
|
+
};
|
|
138
|
+
webhookSubscriber.addWebhook(webhook);
|
|
139
|
+
agent.logger.info(`Webhook registered: ${webhookId} -> ${url}`);
|
|
140
|
+
return ctx.json(
|
|
141
|
+
{
|
|
142
|
+
webhook: {
|
|
143
|
+
id: webhook.id,
|
|
144
|
+
url: webhook.url,
|
|
145
|
+
description: webhook.description,
|
|
146
|
+
createdAt: webhook.createdAt
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
201
|
|
150
|
+
);
|
|
151
|
+
}).openapi(listRoute, async (ctx) => {
|
|
152
|
+
const webhooks = webhookSubscriber.getWebhooks().map((webhook) => ({
|
|
153
|
+
id: webhook.id,
|
|
154
|
+
url: webhook.url,
|
|
155
|
+
description: webhook.description,
|
|
156
|
+
createdAt: webhook.createdAt
|
|
157
|
+
}));
|
|
158
|
+
return ctx.json({ webhooks });
|
|
159
|
+
}).openapi(getRoute, (ctx) => {
|
|
160
|
+
const { webhookId } = ctx.req.valid("param");
|
|
161
|
+
const webhook = webhookSubscriber.getWebhook(webhookId);
|
|
162
|
+
if (!webhook) {
|
|
163
|
+
return ctx.json({ error: "Webhook not found" }, 404);
|
|
164
|
+
}
|
|
165
|
+
return ctx.json({
|
|
166
|
+
webhook: {
|
|
167
|
+
id: webhook.id,
|
|
168
|
+
url: webhook.url,
|
|
169
|
+
description: webhook.description,
|
|
170
|
+
createdAt: webhook.createdAt
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}).openapi(deleteRoute, (ctx) => {
|
|
174
|
+
const agent = getAgent();
|
|
175
|
+
const { webhookId } = ctx.req.valid("param");
|
|
176
|
+
const removed = webhookSubscriber.removeWebhook(webhookId);
|
|
177
|
+
if (!removed) {
|
|
178
|
+
return ctx.json({ error: "Webhook not found" }, 404);
|
|
179
|
+
}
|
|
180
|
+
agent.logger.info(`Webhook removed: ${webhookId}`);
|
|
181
|
+
return ctx.json({ status: "removed", webhookId });
|
|
182
|
+
}).openapi(testRoute, async (ctx) => {
|
|
183
|
+
const agent = getAgent();
|
|
184
|
+
const { webhookId } = ctx.req.valid("param");
|
|
185
|
+
const webhook = webhookSubscriber.getWebhook(webhookId);
|
|
186
|
+
if (!webhook) {
|
|
187
|
+
return ctx.json({ error: "Webhook not found" }, 404);
|
|
188
|
+
}
|
|
189
|
+
agent.logger.info(`Testing webhook: ${webhookId}`);
|
|
190
|
+
const result = await webhookSubscriber.testWebhook(webhookId);
|
|
191
|
+
return ctx.json({
|
|
192
|
+
test: "completed",
|
|
193
|
+
result: {
|
|
194
|
+
success: result.success,
|
|
195
|
+
statusCode: result.statusCode,
|
|
196
|
+
responseTime: result.responseTime,
|
|
197
|
+
error: result.error
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
export {
|
|
203
|
+
createWebhooksRouter
|
|
204
|
+
};
|