@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 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hono/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAezD,OAAO,EAAsB,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAElF,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAKxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AA8B1E,MAAM,MAAM,qBAAqB,GAAG;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,UAAU,CAAC;IAC3B,YAAY,EAAE,MAAM,SAAS,CAAC;IAC9B,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,iBAAiB,EAAE,sBAAsB,CAAC;IAC1C,aAAa,EAAE,qBAAqB,CAAC;IACrC,aAAa,CAAC,EAAE,mBAAmB,CAAC;CACvC,CAAC;AAEF,wBAAgB,cAAc,CAAC,OAAO,EAAE,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBALn96I;AAID,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
+
import { createHealthRouter } from "./routes/health.js";
|
|
3
|
+
import { createGreetingRouter } from "./routes/greeting.js";
|
|
4
|
+
import { createMessagesRouter } from "./routes/messages.js";
|
|
5
|
+
import { createLlmRouter } from "./routes/llm.js";
|
|
6
|
+
import { createSessionsRouter } from "./routes/sessions.js";
|
|
7
|
+
import { createSearchRouter } from "./routes/search.js";
|
|
8
|
+
import { createMcpRouter } from "./routes/mcp.js";
|
|
9
|
+
import { createA2aRouter } from "./routes/a2a.js";
|
|
10
|
+
import { createA2AJsonRpcRouter } from "./routes/a2a-jsonrpc.js";
|
|
11
|
+
import { createA2ATasksRouter } from "./routes/a2a-tasks.js";
|
|
12
|
+
import { createWebhooksRouter } from "./routes/webhooks.js";
|
|
13
|
+
import { createPromptsRouter } from "./routes/prompts.js";
|
|
14
|
+
import { createResourcesRouter } from "./routes/resources.js";
|
|
15
|
+
import { createMemoryRouter } from "./routes/memory.js";
|
|
16
|
+
import { createAgentsRouter } from "./routes/agents.js";
|
|
17
|
+
import { createApprovalsRouter } from "./routes/approvals.js";
|
|
18
|
+
import { handleHonoError } from "./middleware/error.js";
|
|
19
|
+
import { prettyJsonMiddleware, redactionMiddleware } from "./middleware/redaction.js";
|
|
20
|
+
import { createCorsMiddleware } from "./middleware/cors.js";
|
|
21
|
+
import { createAuthMiddleware } from "./middleware/auth.js";
|
|
22
|
+
import { readFileSync } from "node:fs";
|
|
23
|
+
import { fileURLToPath } from "node:url";
|
|
24
|
+
import { dirname, join } from "node:path";
|
|
25
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
26
|
+
const __dirname = dirname(__filename);
|
|
27
|
+
const packageJson = JSON.parse(readFileSync(join(__dirname, "../../package.json"), "utf-8"));
|
|
28
|
+
const dummyAgentsContext = {
|
|
29
|
+
switchAgentById: async () => {
|
|
30
|
+
throw new Error("Multi-agent features not available in single-agent mode");
|
|
31
|
+
},
|
|
32
|
+
switchAgentByPath: async () => {
|
|
33
|
+
throw new Error("Multi-agent features not available in single-agent mode");
|
|
34
|
+
},
|
|
35
|
+
resolveAgentInfo: async () => {
|
|
36
|
+
throw new Error("Multi-agent features not available in single-agent mode");
|
|
37
|
+
},
|
|
38
|
+
ensureAgentAvailable: () => {
|
|
39
|
+
},
|
|
40
|
+
getActiveAgentId: () => void 0
|
|
41
|
+
};
|
|
42
|
+
function createDextoApp(options) {
|
|
43
|
+
const {
|
|
44
|
+
getAgent,
|
|
45
|
+
getAgentCard,
|
|
46
|
+
approvalCoordinator,
|
|
47
|
+
webhookSubscriber,
|
|
48
|
+
sseSubscriber,
|
|
49
|
+
agentsContext
|
|
50
|
+
} = options;
|
|
51
|
+
const app = new OpenAPIHono({ strict: false });
|
|
52
|
+
app.use("*", createCorsMiddleware());
|
|
53
|
+
app.use("*", createAuthMiddleware());
|
|
54
|
+
app.onError((err, ctx) => handleHonoError(ctx, err));
|
|
55
|
+
app.use("/api/*", prettyJsonMiddleware);
|
|
56
|
+
app.use("/api/*", redactionMiddleware);
|
|
57
|
+
const fullApp = app.route("/health", createHealthRouter(getAgent)).route("/", createA2aRouter(getAgentCard)).route("/", createA2AJsonRpcRouter(getAgent, sseSubscriber)).route("/", createA2ATasksRouter(getAgent, sseSubscriber)).route("/api", createGreetingRouter(getAgent)).route("/api", createMessagesRouter(getAgent, approvalCoordinator)).route("/api", createLlmRouter(getAgent)).route("/api", createSessionsRouter(getAgent)).route("/api", createSearchRouter(getAgent)).route("/api", createMcpRouter(getAgent)).route("/api", createWebhooksRouter(getAgent, webhookSubscriber)).route("/api", createPromptsRouter(getAgent)).route("/api", createResourcesRouter(getAgent)).route("/api", createMemoryRouter(getAgent)).route("/api", createApprovalsRouter(getAgent, approvalCoordinator)).route("/api", createAgentsRouter(getAgent, agentsContext || dummyAgentsContext));
|
|
58
|
+
fullApp.doc("/openapi.json", {
|
|
59
|
+
openapi: "3.0.0",
|
|
60
|
+
info: {
|
|
61
|
+
title: "Dexto API",
|
|
62
|
+
version: packageJson.version,
|
|
63
|
+
description: "OpenAPI spec for the Dexto REST API server"
|
|
64
|
+
},
|
|
65
|
+
servers: [
|
|
66
|
+
{
|
|
67
|
+
url: "http://localhost:3001",
|
|
68
|
+
description: "Local development server (default port)"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
url: "http://localhost:{port}",
|
|
72
|
+
description: "Local development server (custom port)",
|
|
73
|
+
variables: {
|
|
74
|
+
port: {
|
|
75
|
+
default: "3001",
|
|
76
|
+
description: "API server port"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
],
|
|
81
|
+
tags: [
|
|
82
|
+
{
|
|
83
|
+
name: "system",
|
|
84
|
+
description: "System health and status endpoints"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "config",
|
|
88
|
+
description: "Agent configuration and greeting management"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "messages",
|
|
92
|
+
description: "Send messages to the agent and manage conversations"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: "sessions",
|
|
96
|
+
description: "Create and manage conversation sessions"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: "llm",
|
|
100
|
+
description: "Configure and switch between LLM providers and models"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: "mcp",
|
|
104
|
+
description: "Manage Model Context Protocol (MCP) servers and tools"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: "webhooks",
|
|
108
|
+
description: "Register and manage webhook endpoints for agent events"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: "search",
|
|
112
|
+
description: "Search through messages and sessions"
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: "memory",
|
|
116
|
+
description: "Store and retrieve agent memories for context"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: "prompts",
|
|
120
|
+
description: "Manage custom prompts and templates"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: "resources",
|
|
124
|
+
description: "Access and manage resources from MCP servers and internal providers"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: "agent",
|
|
128
|
+
description: "Current agent configuration and file operations"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: "agents",
|
|
132
|
+
description: "Install, switch, and manage agent configurations"
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
});
|
|
136
|
+
Object.assign(fullApp, { webhookSubscriber });
|
|
137
|
+
return fullApp;
|
|
138
|
+
}
|
|
139
|
+
export {
|
|
140
|
+
createDextoApp
|
|
141
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
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 auth_exports = {};
|
|
20
|
+
__export(auth_exports, {
|
|
21
|
+
createAuthMiddleware: () => createAuthMiddleware
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(auth_exports);
|
|
24
|
+
var import_core = require("@dexto/core");
|
|
25
|
+
const PUBLIC_ROUTES = ["/health", "/.well-known/agent-card.json", "/openapi.json"];
|
|
26
|
+
function createAuthMiddleware() {
|
|
27
|
+
const apiKey = process.env.DEXTO_SERVER_API_KEY;
|
|
28
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
29
|
+
const requireAuth = process.env.DEXTO_SERVER_REQUIRE_AUTH === "true";
|
|
30
|
+
if (isProduction && !apiKey) {
|
|
31
|
+
import_core.logger.warn(
|
|
32
|
+
`\u26A0\uFE0F SECURITY WARNING: Running in production mode (NODE_ENV=production) without DEXTO_SERVER_API_KEY. Dexto Server API is UNPROTECTED. Set DEXTO_SERVER_API_KEY environment variable to secure your API.`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return async (ctx, next) => {
|
|
36
|
+
const path = ctx.req.path;
|
|
37
|
+
if (PUBLIC_ROUTES.some((route) => path === route || path.startsWith(route))) {
|
|
38
|
+
return next();
|
|
39
|
+
}
|
|
40
|
+
if (!isProduction && !requireAuth) {
|
|
41
|
+
return next();
|
|
42
|
+
}
|
|
43
|
+
if (!apiKey) {
|
|
44
|
+
return ctx.json(
|
|
45
|
+
{
|
|
46
|
+
error: "Configuration Error",
|
|
47
|
+
message: requireAuth ? "DEXTO_SERVER_REQUIRE_AUTH=true but DEXTO_SERVER_API_KEY not set. Set DEXTO_SERVER_API_KEY environment variable." : "NODE_ENV=production requires DEXTO_SERVER_API_KEY. Set DEXTO_SERVER_API_KEY environment variable to secure your API."
|
|
48
|
+
},
|
|
49
|
+
500
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
const authHeader = ctx.req.header("Authorization");
|
|
53
|
+
const providedKey = authHeader?.replace(/^Bearer\s+/i, "");
|
|
54
|
+
if (!providedKey || providedKey !== apiKey) {
|
|
55
|
+
import_core.logger.warn("Unauthorized API access attempt", {
|
|
56
|
+
path,
|
|
57
|
+
hasKey: !!providedKey,
|
|
58
|
+
origin: ctx.req.header("origin"),
|
|
59
|
+
userAgent: ctx.req.header("user-agent")
|
|
60
|
+
});
|
|
61
|
+
return ctx.json(
|
|
62
|
+
{
|
|
63
|
+
error: "Unauthorized",
|
|
64
|
+
message: "Invalid or missing API key. Provide Authorization: Bearer <api-key> header."
|
|
65
|
+
},
|
|
66
|
+
401
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
await next();
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
74
|
+
createAuthMiddleware
|
|
75
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/hono/middleware/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAuB9C,wBAAgB,oBAAoB,IAAI,iBAAiB,CAiExD"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { logger } from "@dexto/core";
|
|
2
|
+
const PUBLIC_ROUTES = ["/health", "/.well-known/agent-card.json", "/openapi.json"];
|
|
3
|
+
function createAuthMiddleware() {
|
|
4
|
+
const apiKey = process.env.DEXTO_SERVER_API_KEY;
|
|
5
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
6
|
+
const requireAuth = process.env.DEXTO_SERVER_REQUIRE_AUTH === "true";
|
|
7
|
+
if (isProduction && !apiKey) {
|
|
8
|
+
logger.warn(
|
|
9
|
+
`\u26A0\uFE0F SECURITY WARNING: Running in production mode (NODE_ENV=production) without DEXTO_SERVER_API_KEY. Dexto Server API is UNPROTECTED. Set DEXTO_SERVER_API_KEY environment variable to secure your API.`
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
return async (ctx, next) => {
|
|
13
|
+
const path = ctx.req.path;
|
|
14
|
+
if (PUBLIC_ROUTES.some((route) => path === route || path.startsWith(route))) {
|
|
15
|
+
return next();
|
|
16
|
+
}
|
|
17
|
+
if (!isProduction && !requireAuth) {
|
|
18
|
+
return next();
|
|
19
|
+
}
|
|
20
|
+
if (!apiKey) {
|
|
21
|
+
return ctx.json(
|
|
22
|
+
{
|
|
23
|
+
error: "Configuration Error",
|
|
24
|
+
message: requireAuth ? "DEXTO_SERVER_REQUIRE_AUTH=true but DEXTO_SERVER_API_KEY not set. Set DEXTO_SERVER_API_KEY environment variable." : "NODE_ENV=production requires DEXTO_SERVER_API_KEY. Set DEXTO_SERVER_API_KEY environment variable to secure your API."
|
|
25
|
+
},
|
|
26
|
+
500
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
const authHeader = ctx.req.header("Authorization");
|
|
30
|
+
const providedKey = authHeader?.replace(/^Bearer\s+/i, "");
|
|
31
|
+
if (!providedKey || providedKey !== apiKey) {
|
|
32
|
+
logger.warn("Unauthorized API access attempt", {
|
|
33
|
+
path,
|
|
34
|
+
hasKey: !!providedKey,
|
|
35
|
+
origin: ctx.req.header("origin"),
|
|
36
|
+
userAgent: ctx.req.header("user-agent")
|
|
37
|
+
});
|
|
38
|
+
return ctx.json(
|
|
39
|
+
{
|
|
40
|
+
error: "Unauthorized",
|
|
41
|
+
message: "Invalid or missing API key. Provide Authorization: Bearer <api-key> header."
|
|
42
|
+
},
|
|
43
|
+
401
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
await next();
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
createAuthMiddleware
|
|
51
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
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 cors_exports = {};
|
|
20
|
+
__export(cors_exports, {
|
|
21
|
+
createCorsMiddleware: () => createCorsMiddleware
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(cors_exports);
|
|
24
|
+
var import_cors = require("hono/cors");
|
|
25
|
+
function createCorsMiddleware() {
|
|
26
|
+
return (0, import_cors.cors)({
|
|
27
|
+
origin: (origin) => {
|
|
28
|
+
if (!origin) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const originUrl = new URL(origin);
|
|
33
|
+
const hostname = originUrl.hostname;
|
|
34
|
+
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1") {
|
|
35
|
+
return origin;
|
|
36
|
+
}
|
|
37
|
+
const customOrigins = process.env.DEXTO_ALLOWED_ORIGINS;
|
|
38
|
+
if (customOrigins) {
|
|
39
|
+
const allowedList = customOrigins.split(",").map((o) => o.trim());
|
|
40
|
+
if (allowedList.includes(origin)) {
|
|
41
|
+
return origin;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
} catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
allowMethods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"],
|
|
50
|
+
allowHeaders: ["Content-Type", "Authorization"],
|
|
51
|
+
credentials: true
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
+
0 && (module.exports = {
|
|
56
|
+
createCorsMiddleware
|
|
57
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MiddlewareHandler } from 'hono';
|
|
2
|
+
/**
|
|
3
|
+
* CORS middleware that allows:
|
|
4
|
+
* 1. All localhost/127.0.0.1 origins on any port (for local development)
|
|
5
|
+
* 2. Custom origins specified in DEXTO_ALLOWED_ORIGINS environment variable
|
|
6
|
+
* 3. Server-to-server requests with no origin header
|
|
7
|
+
*/
|
|
8
|
+
export declare function createCorsMiddleware(): MiddlewareHandler;
|
|
9
|
+
//# sourceMappingURL=cors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cors.d.ts","sourceRoot":"","sources":["../../../src/hono/middleware/cors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAE9C;;;;;GAKG;AACH,wBAAgB,oBAAoB,IAAI,iBAAiB,CAuCxD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { cors } from "hono/cors";
|
|
2
|
+
function createCorsMiddleware() {
|
|
3
|
+
return cors({
|
|
4
|
+
origin: (origin) => {
|
|
5
|
+
if (!origin) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
try {
|
|
9
|
+
const originUrl = new URL(origin);
|
|
10
|
+
const hostname = originUrl.hostname;
|
|
11
|
+
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1") {
|
|
12
|
+
return origin;
|
|
13
|
+
}
|
|
14
|
+
const customOrigins = process.env.DEXTO_ALLOWED_ORIGINS;
|
|
15
|
+
if (customOrigins) {
|
|
16
|
+
const allowedList = customOrigins.split(",").map((o) => o.trim());
|
|
17
|
+
if (allowedList.includes(origin)) {
|
|
18
|
+
return origin;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
} catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
allowMethods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"],
|
|
27
|
+
allowHeaders: ["Content-Type", "Authorization"],
|
|
28
|
+
credentials: true
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
createCorsMiddleware
|
|
33
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
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 error_exports = {};
|
|
20
|
+
__export(error_exports, {
|
|
21
|
+
handleHonoError: () => handleHonoError,
|
|
22
|
+
mapErrorTypeToStatus: () => mapErrorTypeToStatus,
|
|
23
|
+
statusForValidation: () => statusForValidation
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(error_exports);
|
|
26
|
+
var import_core = require("@dexto/core");
|
|
27
|
+
var import_core2 = require("@dexto/core");
|
|
28
|
+
var import_zod = require("zod");
|
|
29
|
+
const mapErrorTypeToStatus = (type) => {
|
|
30
|
+
switch (type) {
|
|
31
|
+
case import_core.ErrorType.USER:
|
|
32
|
+
return 400;
|
|
33
|
+
case import_core.ErrorType.NOT_FOUND:
|
|
34
|
+
return 404;
|
|
35
|
+
case import_core.ErrorType.FORBIDDEN:
|
|
36
|
+
return 403;
|
|
37
|
+
case import_core.ErrorType.TIMEOUT:
|
|
38
|
+
return 408;
|
|
39
|
+
case import_core.ErrorType.RATE_LIMIT:
|
|
40
|
+
return 429;
|
|
41
|
+
case import_core.ErrorType.SYSTEM:
|
|
42
|
+
return 500;
|
|
43
|
+
case import_core.ErrorType.THIRD_PARTY:
|
|
44
|
+
return 502;
|
|
45
|
+
case import_core.ErrorType.UNKNOWN:
|
|
46
|
+
default:
|
|
47
|
+
return 500;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const statusForValidation = (issues) => {
|
|
51
|
+
const firstError = issues.find((i) => i.severity === "error");
|
|
52
|
+
const type = firstError?.type ?? import_core.ErrorType.USER;
|
|
53
|
+
return mapErrorTypeToStatus(type);
|
|
54
|
+
};
|
|
55
|
+
function handleHonoError(ctx, err) {
|
|
56
|
+
const endpoint = ctx.req.path || "unknown";
|
|
57
|
+
const method = ctx.req.method || "unknown";
|
|
58
|
+
if (err instanceof import_core.DextoRuntimeError) {
|
|
59
|
+
return ctx.json(
|
|
60
|
+
{
|
|
61
|
+
...err.toJSON(),
|
|
62
|
+
endpoint,
|
|
63
|
+
method
|
|
64
|
+
},
|
|
65
|
+
mapErrorTypeToStatus(err.type)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
if (err instanceof import_core.DextoValidationError) {
|
|
69
|
+
return ctx.json(
|
|
70
|
+
{
|
|
71
|
+
...err.toJSON(),
|
|
72
|
+
endpoint,
|
|
73
|
+
method
|
|
74
|
+
},
|
|
75
|
+
statusForValidation(err.issues)
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
if (err instanceof import_zod.ZodError) {
|
|
79
|
+
const issues = (0, import_core.zodToIssues)(err);
|
|
80
|
+
const dexErr = new import_core.DextoValidationError(issues);
|
|
81
|
+
return ctx.json(
|
|
82
|
+
{
|
|
83
|
+
...dexErr.toJSON(),
|
|
84
|
+
endpoint,
|
|
85
|
+
method
|
|
86
|
+
},
|
|
87
|
+
statusForValidation(issues)
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
if (err instanceof SyntaxError) {
|
|
91
|
+
return ctx.json(
|
|
92
|
+
{
|
|
93
|
+
code: "invalid_json",
|
|
94
|
+
message: err.message || "Invalid JSON body",
|
|
95
|
+
scope: "agent",
|
|
96
|
+
type: "user",
|
|
97
|
+
severity: "error",
|
|
98
|
+
endpoint,
|
|
99
|
+
method
|
|
100
|
+
},
|
|
101
|
+
400
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
105
|
+
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
106
|
+
import_core2.logger.error(
|
|
107
|
+
`Unhandled error in API middleware: ${errorMessage}, endpoint: ${method} ${endpoint}, stack: ${errorStack}, type: ${typeof err}`
|
|
108
|
+
);
|
|
109
|
+
const isDevelopment = process.env.NODE_ENV === "development";
|
|
110
|
+
const userMessage = isDevelopment ? `An unexpected error occurred: ${errorMessage}` : "An unexpected error occurred. Please try again later.";
|
|
111
|
+
return ctx.json(
|
|
112
|
+
{
|
|
113
|
+
code: "internal_error",
|
|
114
|
+
message: userMessage,
|
|
115
|
+
scope: "system",
|
|
116
|
+
type: "system",
|
|
117
|
+
severity: "error",
|
|
118
|
+
endpoint,
|
|
119
|
+
method,
|
|
120
|
+
// Only include stack traces in development to avoid exposing internals
|
|
121
|
+
...isDevelopment && errorStack ? { stack: errorStack } : {}
|
|
122
|
+
},
|
|
123
|
+
500
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
127
|
+
0 && (module.exports = {
|
|
128
|
+
handleHonoError,
|
|
129
|
+
mapErrorTypeToStatus,
|
|
130
|
+
statusForValidation
|
|
131
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ErrorType, zodToIssues } from '@dexto/core';
|
|
2
|
+
export declare const mapErrorTypeToStatus: (type: ErrorType) => number;
|
|
3
|
+
export declare const statusForValidation: (issues: ReturnType<typeof zodToIssues>) => number;
|
|
4
|
+
export declare function handleHonoError(ctx: any, err: unknown): any;
|
|
5
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../src/hono/middleware/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2C,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI9F,eAAO,MAAM,oBAAoB,GAAI,MAAM,SAAS,KAAG,MAoBtD,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,QAAQ,UAAU,CAAC,OAAO,WAAW,CAAC,KAAG,MAI5E,CAAC;AAEF,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,OAkFrD"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { DextoRuntimeError, DextoValidationError, ErrorType, zodToIssues } from "@dexto/core";
|
|
2
|
+
import { logger } from "@dexto/core";
|
|
3
|
+
import { ZodError } from "zod";
|
|
4
|
+
const mapErrorTypeToStatus = (type) => {
|
|
5
|
+
switch (type) {
|
|
6
|
+
case ErrorType.USER:
|
|
7
|
+
return 400;
|
|
8
|
+
case ErrorType.NOT_FOUND:
|
|
9
|
+
return 404;
|
|
10
|
+
case ErrorType.FORBIDDEN:
|
|
11
|
+
return 403;
|
|
12
|
+
case ErrorType.TIMEOUT:
|
|
13
|
+
return 408;
|
|
14
|
+
case ErrorType.RATE_LIMIT:
|
|
15
|
+
return 429;
|
|
16
|
+
case ErrorType.SYSTEM:
|
|
17
|
+
return 500;
|
|
18
|
+
case ErrorType.THIRD_PARTY:
|
|
19
|
+
return 502;
|
|
20
|
+
case ErrorType.UNKNOWN:
|
|
21
|
+
default:
|
|
22
|
+
return 500;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const statusForValidation = (issues) => {
|
|
26
|
+
const firstError = issues.find((i) => i.severity === "error");
|
|
27
|
+
const type = firstError?.type ?? ErrorType.USER;
|
|
28
|
+
return mapErrorTypeToStatus(type);
|
|
29
|
+
};
|
|
30
|
+
function handleHonoError(ctx, err) {
|
|
31
|
+
const endpoint = ctx.req.path || "unknown";
|
|
32
|
+
const method = ctx.req.method || "unknown";
|
|
33
|
+
if (err instanceof DextoRuntimeError) {
|
|
34
|
+
return ctx.json(
|
|
35
|
+
{
|
|
36
|
+
...err.toJSON(),
|
|
37
|
+
endpoint,
|
|
38
|
+
method
|
|
39
|
+
},
|
|
40
|
+
mapErrorTypeToStatus(err.type)
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
if (err instanceof DextoValidationError) {
|
|
44
|
+
return ctx.json(
|
|
45
|
+
{
|
|
46
|
+
...err.toJSON(),
|
|
47
|
+
endpoint,
|
|
48
|
+
method
|
|
49
|
+
},
|
|
50
|
+
statusForValidation(err.issues)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
if (err instanceof ZodError) {
|
|
54
|
+
const issues = zodToIssues(err);
|
|
55
|
+
const dexErr = new DextoValidationError(issues);
|
|
56
|
+
return ctx.json(
|
|
57
|
+
{
|
|
58
|
+
...dexErr.toJSON(),
|
|
59
|
+
endpoint,
|
|
60
|
+
method
|
|
61
|
+
},
|
|
62
|
+
statusForValidation(issues)
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
if (err instanceof SyntaxError) {
|
|
66
|
+
return ctx.json(
|
|
67
|
+
{
|
|
68
|
+
code: "invalid_json",
|
|
69
|
+
message: err.message || "Invalid JSON body",
|
|
70
|
+
scope: "agent",
|
|
71
|
+
type: "user",
|
|
72
|
+
severity: "error",
|
|
73
|
+
endpoint,
|
|
74
|
+
method
|
|
75
|
+
},
|
|
76
|
+
400
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
80
|
+
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
81
|
+
logger.error(
|
|
82
|
+
`Unhandled error in API middleware: ${errorMessage}, endpoint: ${method} ${endpoint}, stack: ${errorStack}, type: ${typeof err}`
|
|
83
|
+
);
|
|
84
|
+
const isDevelopment = process.env.NODE_ENV === "development";
|
|
85
|
+
const userMessage = isDevelopment ? `An unexpected error occurred: ${errorMessage}` : "An unexpected error occurred. Please try again later.";
|
|
86
|
+
return ctx.json(
|
|
87
|
+
{
|
|
88
|
+
code: "internal_error",
|
|
89
|
+
message: userMessage,
|
|
90
|
+
scope: "system",
|
|
91
|
+
type: "system",
|
|
92
|
+
severity: "error",
|
|
93
|
+
endpoint,
|
|
94
|
+
method,
|
|
95
|
+
// Only include stack traces in development to avoid exposing internals
|
|
96
|
+
...isDevelopment && errorStack ? { stack: errorStack } : {}
|
|
97
|
+
},
|
|
98
|
+
500
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
export {
|
|
102
|
+
handleHonoError,
|
|
103
|
+
mapErrorTypeToStatus,
|
|
104
|
+
statusForValidation
|
|
105
|
+
};
|