@open-wa/api 5.0.0 → 5.2.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/dashboard-neo/dist/assets/{AgentScalarDrawer.vue-BGBDvSQB.js → AgentScalarDrawer.vue-Cly13x9l.js} +3 -3
- package/dashboard-neo/dist/assets/index-CP58_PDI.css +1 -0
- package/dashboard-neo/dist/assets/index-Dl0sJuu6.js +2162 -0
- package/dashboard-neo/dist/assets/{modal-CKSoZwLD.js → modal-BTlJ4pQT.js} +1 -1
- package/dashboard-neo/dist/index.html +2 -2
- package/dist/index.cjs +167 -8
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/package.json +5 -4
- package/src/auth/api-key.ts +28 -0
- package/src/compat/args.ts +1 -0
- package/src/compat/deprecation.ts +35 -0
- package/src/compat/session-path.ts +19 -0
- package/src/createApiMiddleware.ts +184 -0
- package/src/createApiServer.ts +472 -0
- package/src/dashboard/middleware.ts +94 -0
- package/src/diagnostics/DiagnosticStore.ts +99 -0
- package/src/docs/openapi.ts +132 -0
- package/src/docs/postman.ts +42 -0
- package/src/events/EventBridge.ts +4 -0
- package/src/events/EventBroadcaster.ts +126 -0
- package/src/execution/kernel.ts +1 -0
- package/src/health/HealthStore.ts +252 -0
- package/src/index.ts +9 -0
- package/src/invoke-client-method.ts +1 -0
- package/src/middleware/rate-limit.ts +30 -0
- package/src/monitoring/elastic.ts +104 -0
- package/src/routes/agent-discovery.ts +150 -0
- package/src/routes/debug.ts +114 -0
- package/src/routes/meta.ts +512 -0
- package/src/types.ts +31 -0
- package/src/version.ts +4 -0
- package/dashboard-neo/dist/assets/index-DM5k7cbF.css +0 -1
- package/dashboard-neo/dist/assets/index-rjufqWkX.js +0 -2149
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Client as ElasticClient } from '@elastic/elasticsearch';
|
|
2
|
+
|
|
3
|
+
export interface ElasticConfig {
|
|
4
|
+
url: string;
|
|
5
|
+
username?: string;
|
|
6
|
+
password?: string;
|
|
7
|
+
bufferSize?: number;
|
|
8
|
+
pipeline?: string;
|
|
9
|
+
indexPrefix?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ElasticDoc {
|
|
13
|
+
timestamp: string;
|
|
14
|
+
level?: 'info' | 'warn' | 'error' | 'debug';
|
|
15
|
+
message: string;
|
|
16
|
+
component?: string;
|
|
17
|
+
sessionId?: string;
|
|
18
|
+
schemaId?: string;
|
|
19
|
+
requestId?: string;
|
|
20
|
+
driver?: string;
|
|
21
|
+
method?: string;
|
|
22
|
+
event?: string;
|
|
23
|
+
duration?: number;
|
|
24
|
+
statusCode?: number;
|
|
25
|
+
userAgent?: string;
|
|
26
|
+
ip?: string;
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class ElasticEmitter {
|
|
31
|
+
private client: ElasticClient;
|
|
32
|
+
private config: ElasticConfig;
|
|
33
|
+
private buffer: ElasticDoc[] = [];
|
|
34
|
+
private flushInterval?: NodeJS.Timeout;
|
|
35
|
+
|
|
36
|
+
constructor(config: ElasticConfig) {
|
|
37
|
+
this.config = {
|
|
38
|
+
bufferSize: 50,
|
|
39
|
+
indexPrefix: 'open-wa-',
|
|
40
|
+
...config,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
this.client = new ElasticClient({
|
|
44
|
+
node: this.config.url,
|
|
45
|
+
auth:
|
|
46
|
+
this.config.username && this.config.password
|
|
47
|
+
? {
|
|
48
|
+
username: this.config.username,
|
|
49
|
+
password: this.config.password,
|
|
50
|
+
}
|
|
51
|
+
: undefined,
|
|
52
|
+
maxRetries: 3,
|
|
53
|
+
requestTimeout: 5000,
|
|
54
|
+
sniffOnStart: true,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public async start(): Promise<void> {
|
|
59
|
+
await this.client.ping();
|
|
60
|
+
this.flushInterval = setInterval(() => {
|
|
61
|
+
void this.flush();
|
|
62
|
+
}, 10000);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public log(logEntry: Omit<ElasticDoc, 'timestamp'>): void {
|
|
66
|
+
this.buffer.push({
|
|
67
|
+
timestamp: new Date().toISOString(),
|
|
68
|
+
level: logEntry.level || 'info',
|
|
69
|
+
...logEntry,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
if (this.buffer.length >= (this.config.bufferSize || 50)) {
|
|
73
|
+
void this.flush();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public async flush(): Promise<void> {
|
|
78
|
+
if (this.buffer.length === 0) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const docs = [...this.buffer];
|
|
83
|
+
this.buffer = [];
|
|
84
|
+
const indexName = `${this.config.indexPrefix}${new Date().toISOString().split('T')[0]}`;
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
await this.client.bulk({
|
|
88
|
+
body: docs.flatMap((document) => [{ index: { _index: indexName } }, document]),
|
|
89
|
+
});
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.error('Failed to flush to ElasticSearch:', error);
|
|
92
|
+
this.buffer.unshift(...docs);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public async stop(): Promise<void> {
|
|
97
|
+
if (this.flushInterval) {
|
|
98
|
+
clearInterval(this.flushInterval);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
await this.flush();
|
|
102
|
+
await this.client.close();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { Config, HttpMethodDefinition } from '@open-wa/schema';
|
|
2
|
+
|
|
3
|
+
function getExternalBase(c: any) {
|
|
4
|
+
return c.req.header('x-openwa-external-base') || '';
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function joinPath(...parts: string[]) {
|
|
8
|
+
const normalized = parts
|
|
9
|
+
.filter(Boolean)
|
|
10
|
+
.map((part, index) => {
|
|
11
|
+
if (index === 0) {
|
|
12
|
+
return part.replace(/\/+$/, '');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return part.replace(/^\/+/, '').replace(/\/+$/, '');
|
|
16
|
+
})
|
|
17
|
+
.filter(Boolean)
|
|
18
|
+
.join('/');
|
|
19
|
+
|
|
20
|
+
return normalized.startsWith('/') ? normalized : `/${normalized}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function registerAgentDiscoveryRoutes(
|
|
24
|
+
app: any,
|
|
25
|
+
options: { config: Config; methodDefinitions: HttpMethodDefinition[] }
|
|
26
|
+
) {
|
|
27
|
+
app.get('/robots.txt', (c: any) => {
|
|
28
|
+
const origin = new URL(c.req.url).origin;
|
|
29
|
+
const sitemapUrl = joinPath(origin, 'sitemap.xml');
|
|
30
|
+
const content = `User-agent: GPTBot
|
|
31
|
+
Allow: /
|
|
32
|
+
|
|
33
|
+
User-agent: Claude-Web
|
|
34
|
+
Allow: /
|
|
35
|
+
|
|
36
|
+
User-agent: *
|
|
37
|
+
Allow: /
|
|
38
|
+
|
|
39
|
+
Sitemap: ${sitemapUrl}
|
|
40
|
+
`;
|
|
41
|
+
// Add Content-Signal header for isitagentready check
|
|
42
|
+
c.header('Content-Signal', 'ai-train=no, search=yes, ai-input=no');
|
|
43
|
+
return c.text(content);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
app.get('/sitemap.xml', (c: any) => {
|
|
47
|
+
const origin = new URL(c.req.url).origin;
|
|
48
|
+
const now = new Date().toISOString();
|
|
49
|
+
const content = `<?xml version="1.0" encoding="UTF-8"?>
|
|
50
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
51
|
+
<url>
|
|
52
|
+
<loc>${origin}/</loc>
|
|
53
|
+
<lastmod>${now}</lastmod>
|
|
54
|
+
<changefreq>daily</changefreq>
|
|
55
|
+
<priority>1.0</priority>
|
|
56
|
+
</url>
|
|
57
|
+
<url>
|
|
58
|
+
<loc>${origin}/api-docs</loc>
|
|
59
|
+
<lastmod>${now}</lastmod>
|
|
60
|
+
<changefreq>weekly</changefreq>
|
|
61
|
+
<priority>0.8</priority>
|
|
62
|
+
</url>
|
|
63
|
+
</urlset>`;
|
|
64
|
+
c.header('Content-Type', 'application/xml');
|
|
65
|
+
return c.text(content);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
app.get('/.well-known/http-message-signatures-directory', (c: any) => {
|
|
69
|
+
return c.json({ keys: [] });
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
app.get('/.well-known/api-catalog', (c: any) => {
|
|
73
|
+
const origin = new URL(c.req.url).origin;
|
|
74
|
+
c.header('Content-Type', 'application/linkset+json');
|
|
75
|
+
return c.json({
|
|
76
|
+
linkset: [
|
|
77
|
+
{
|
|
78
|
+
anchor: joinPath(origin, 'api'),
|
|
79
|
+
'service-desc': [{ href: joinPath(origin, 'api-docs') }],
|
|
80
|
+
status: [{ href: joinPath(origin, 'health') }],
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
app.get('/.well-known/oauth-authorization-server', (c: any) => {
|
|
87
|
+
const origin = new URL(c.req.url).origin;
|
|
88
|
+
return c.json({
|
|
89
|
+
issuer: origin,
|
|
90
|
+
authorization_endpoint: joinPath(origin, 'api'),
|
|
91
|
+
token_endpoint: joinPath(origin, 'api'),
|
|
92
|
+
grant_types_supported: ["client_credentials"],
|
|
93
|
+
note: "Easy API uses X-API-Key headers strictly for authentication."
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
app.get('/.well-known/openid-configuration', (c: any) => {
|
|
98
|
+
// Alias for OAuth Auth Server
|
|
99
|
+
const origin = new URL(c.req.url).origin;
|
|
100
|
+
return c.json({
|
|
101
|
+
issuer: origin,
|
|
102
|
+
authorization_endpoint: joinPath(origin, 'api'),
|
|
103
|
+
token_endpoint: joinPath(origin, 'api'),
|
|
104
|
+
grant_types_supported: ["client_credentials"],
|
|
105
|
+
note: "Easy API uses X-API-Key headers strictly for authentication."
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
app.get('/.well-known/oauth-protected-resource', (c: any) => {
|
|
110
|
+
const origin = new URL(c.req.url).origin;
|
|
111
|
+
return c.json({
|
|
112
|
+
resource: joinPath(origin, 'api'),
|
|
113
|
+
authorization_servers: [origin],
|
|
114
|
+
scopes_supported: ["all"],
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
app.get('/.well-known/mcp/server-card.json', (c: any) => {
|
|
119
|
+
const endpoint = options.config.mcp?.path || '/mcp';
|
|
120
|
+
return c.json({
|
|
121
|
+
serverInfo: { name: "open-wa", version: "5.0.0" },
|
|
122
|
+
transport: { type: "sse", endpoint },
|
|
123
|
+
capabilities: {}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
app.get('/.well-known/agent-card.json', (c: any) => {
|
|
128
|
+
return c.json({
|
|
129
|
+
name: "open-wa-bot",
|
|
130
|
+
version: "5.0.0",
|
|
131
|
+
supportedInterfaces: ["mcp"]
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
app.get('/.well-known/agent-skills/index.json', (c: any) => {
|
|
136
|
+
const origin = new URL(c.req.url).origin;
|
|
137
|
+
return c.json({
|
|
138
|
+
$schema: "https://agentskills.io/schema.json",
|
|
139
|
+
skills: [
|
|
140
|
+
{
|
|
141
|
+
name: "check-health",
|
|
142
|
+
type: "rest",
|
|
143
|
+
description: "Check session health",
|
|
144
|
+
url: joinPath(origin, 'health'),
|
|
145
|
+
digest: "sha256-dummy",
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debug routes for the dashboard.
|
|
3
|
+
*
|
|
4
|
+
* Provides memory metrics, runtime config dump, and integration config CRUD.
|
|
5
|
+
* These are consumed by the dashboard-neo debug and integrations pages.
|
|
6
|
+
*/
|
|
7
|
+
import type { Config } from '@open-wa/schema';
|
|
8
|
+
|
|
9
|
+
export function registerDebugRoutes(
|
|
10
|
+
app: any,
|
|
11
|
+
options: {
|
|
12
|
+
config: Config;
|
|
13
|
+
getConfig: () => Config;
|
|
14
|
+
getDiagnostics: () => {
|
|
15
|
+
available: boolean;
|
|
16
|
+
captureSource: 'session event bridge';
|
|
17
|
+
captureLimit: number;
|
|
18
|
+
records: unknown[];
|
|
19
|
+
};
|
|
20
|
+
setIntegration?: (id: string, data: { enabled: boolean; config: Record<string, string> }) => void;
|
|
21
|
+
}
|
|
22
|
+
) {
|
|
23
|
+
// Error records can contain runtime details, so require the configured Easy API key.
|
|
24
|
+
app.get('/meta/debug/diagnostics', (c: any) => {
|
|
25
|
+
const apiKey = options.config.apiKey;
|
|
26
|
+
if (!apiKey || c.req.header('X-API-Key') !== apiKey) {
|
|
27
|
+
return c.json({ error: 'Unauthorized', details: 'Invalid or missing API key' }, 401);
|
|
28
|
+
}
|
|
29
|
+
return c.json(options.getDiagnostics());
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// ─── Memory Metrics ──────────────────────────────────────────────
|
|
33
|
+
app.get('/meta/debug/memory', (c: any) => {
|
|
34
|
+
const mem = process.memoryUsage();
|
|
35
|
+
return c.json({
|
|
36
|
+
heapUsed: mem.heapUsed,
|
|
37
|
+
heapTotal: mem.heapTotal,
|
|
38
|
+
rss: mem.rss,
|
|
39
|
+
external: mem.external,
|
|
40
|
+
arrayBuffers: mem.arrayBuffers,
|
|
41
|
+
timestamp: Date.now(),
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// ─── Runtime Config (redacted) ───────────────────────────────────
|
|
46
|
+
app.get('/meta/debug/config', (c: any) => {
|
|
47
|
+
const config = options.getConfig();
|
|
48
|
+
// Redact sensitive fields
|
|
49
|
+
const redacted = { ...config } as Record<string, unknown>;
|
|
50
|
+
const sensitiveKeys = ['apiKey', 'licenseKey', 'elasticPassword', 'elasticUsername'];
|
|
51
|
+
for (const key of sensitiveKeys) {
|
|
52
|
+
if (redacted[key]) {
|
|
53
|
+
redacted[key] = '***REDACTED***';
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Redact nested secrets
|
|
57
|
+
if (redacted.proxyServerCredentials) {
|
|
58
|
+
redacted.proxyServerCredentials = { ...redacted.proxyServerCredentials as Record<string, unknown>, password: '***REDACTED***' };
|
|
59
|
+
}
|
|
60
|
+
if (redacted.s3Sync) {
|
|
61
|
+
redacted.s3Sync = { ...redacted.s3Sync as Record<string, unknown>, secretAccessKey: '***REDACTED***' };
|
|
62
|
+
}
|
|
63
|
+
return c.json(redacted);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// ─── Process Info ────────────────────────────────────────────────
|
|
67
|
+
app.get('/meta/debug/info', (c: any) => {
|
|
68
|
+
return c.json({
|
|
69
|
+
nodeVersion: process.version,
|
|
70
|
+
platform: process.platform,
|
|
71
|
+
arch: process.arch,
|
|
72
|
+
pid: process.pid,
|
|
73
|
+
uptime: process.uptime(),
|
|
74
|
+
cwd: process.cwd(),
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// ─── Integrations CRUD ──────────────────────────────────────────
|
|
79
|
+
app.get('/meta/integrations', (c: any) => {
|
|
80
|
+
const config = options.getConfig();
|
|
81
|
+
return c.json(config.integrations || {});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
app.put('/meta/integrations/:id', async (c: any) => {
|
|
85
|
+
const id = c.req.param('id');
|
|
86
|
+
const body = await c.req.json();
|
|
87
|
+
const { enabled, config: integConfig } = body as {
|
|
88
|
+
enabled: boolean;
|
|
89
|
+
config: Record<string, string>;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
if (options.setIntegration) {
|
|
93
|
+
options.setIntegration(id, { enabled, config: integConfig });
|
|
94
|
+
return c.json({ success: true, message: `Integration '${id}' updated. Restart session to apply changes.` });
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return c.json({ success: false, message: 'Integration management not available' }, 501);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
app.patch('/meta/integrations/:id', async (c: any) => {
|
|
101
|
+
const id = c.req.param('id');
|
|
102
|
+
const body = await c.req.json();
|
|
103
|
+
const { enabled } = body as { enabled: boolean };
|
|
104
|
+
|
|
105
|
+
if (options.setIntegration) {
|
|
106
|
+
const config = options.getConfig();
|
|
107
|
+
const existing = config.integrations?.[id] || { enabled: false, config: {} };
|
|
108
|
+
options.setIntegration(id, { ...existing, enabled });
|
|
109
|
+
return c.json({ success: true, message: `Integration '${id}' ${enabled ? 'enabled' : 'disabled'}. Restart session to apply.` });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return c.json({ success: false, message: 'Integration management not available' }, 501);
|
|
113
|
+
});
|
|
114
|
+
}
|