@open-wa/api 5.0.0-alpha.3 → 5.0.0-alpha.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/dashboard-neo/dist/assets/AgentScalarChatInterface.vue-BEM-e96p.js +18 -0
- package/dashboard-neo/dist/assets/Collection.vue-K8xkab2p.js +1 -0
- package/dashboard-neo/dist/assets/CollectionAuthentication.vue-DpUuH8Ca.js +1 -0
- package/dashboard-neo/dist/assets/CollectionCookies.vue-jgiUddei.js +1 -0
- package/dashboard-neo/dist/assets/CollectionEnvironment.vue-B0oC2CBH.js +1 -0
- package/dashboard-neo/dist/assets/CollectionOverview.vue-C5go3_xX.js +1 -0
- package/dashboard-neo/dist/assets/CollectionScripts.vue-DoZD9KS_.js +1 -0
- package/dashboard-neo/dist/assets/CollectionServers.vue-Dh15RVkK.js +1 -0
- package/dashboard-neo/dist/assets/CollectionSettings.vue-Bo9YqB0V.js +1 -0
- package/dashboard-neo/dist/assets/CollectionSync.vue-CfzmGYPL.js +1 -0
- package/dashboard-neo/dist/assets/Cookies.vue-y9E-rz2Y.js +1 -0
- package/dashboard-neo/dist/assets/DataTableInput.vue-D1oakGxr.js +1 -0
- package/dashboard-neo/dist/assets/DeleteSidebarListElement.vue-CsxnO1Bf.js +1 -0
- package/dashboard-neo/dist/assets/EditSidebarListElement.vue-BLjFSHLy.js +1 -0
- package/dashboard-neo/dist/assets/EmptyState.vue-Dt8wow3H.js +22 -0
- package/dashboard-neo/dist/assets/Environment.vue-Cb7A1mCr.js +1 -0
- package/dashboard-neo/dist/assets/EnvironmentModal.vue-DQS71tA1.js +1 -0
- package/dashboard-neo/dist/assets/Form.vue-CRMOM5yS.js +1 -0
- package/dashboard-neo/dist/assets/IconSelector.vue-m_NkHq-F.js +1 -0
- package/dashboard-neo/dist/assets/Request.vue-Do_GjDpa.js +1 -0
- package/dashboard-neo/dist/assets/RequestAuth.vue-DmCKBgQ0.js +1 -0
- package/dashboard-neo/dist/assets/RequestRoot.vue-BwCfLWGZ.js +19 -0
- package/dashboard-neo/dist/assets/Settings.vue-BXMJh3oE.js +1 -0
- package/dashboard-neo/dist/assets/SidebarButton.vue-Bw3z_ul7.js +1 -0
- package/dashboard-neo/dist/assets/SidebarListElement.vue-B_wb5A8B.js +1 -0
- package/dashboard-neo/dist/assets/basic-shape-diamond.svg-DSX6HE6C.js +1 -0
- package/dashboard-neo/dist/assets/basic-shape-hexagon.svg-D8TPOjRl.js +1 -0
- package/dashboard-neo/dist/assets/basic-shape-primary-circle-ellipse-round.svg-CpVktaCn.js +1 -0
- package/dashboard-neo/dist/assets/basic-shape-primary-square-rectangle.svg-CPu9zgKh.js +1 -0
- package/dashboard-neo/dist/assets/basic-shape-shield.svg-4IKVW7Xp.js +1 -0
- package/dashboard-neo/dist/assets/build-request-security-CGOYAw-J.js +1 -0
- package/dashboard-neo/dist/assets/computer-device-desktop-monitor.svg-1HvbvOnd.js +1 -0
- package/dashboard-neo/dist/assets/computer-device-desktop.svg-CtqcYXx1.js +1 -0
- package/dashboard-neo/dist/assets/computer-device-laptop.svg-B2bM3iWZ.js +1 -0
- package/dashboard-neo/dist/assets/computer-device-mobile-phone-android-samsung-back.svg-CtCumQJw.js +1 -0
- package/dashboard-neo/dist/assets/computer-device-mobile-phone-android-samsung.svg-CTqTksmB.js +1 -0
- package/dashboard-neo/dist/assets/computer-device-mobile-phone-iphone-x-back.svg-BKEERhEs.js +1 -0
- package/dashboard-neo/dist/assets/computer-device-mobile-phone-iphone-x.svg-Eq6WEm3S.js +1 -0
- package/dashboard-neo/dist/assets/computer-device-mobile-tablet-touch.svg-CUKTlTEy.js +1 -0
- package/dashboard-neo/dist/assets/computer-device-mobile-tablet.svg-B835AKCv.js +1 -0
- package/dashboard-neo/dist/assets/computer-device-network-ethernet-cat6.svg-CusgQ5zm.js +1 -0
- package/dashboard-neo/dist/assets/computer-device-network-lan-www.svg-DZYss8vi.js +1 -0
- package/dashboard-neo/dist/assets/computer-device-network-wifi-connection.svg-cILX5shc.js +1 -0
- package/dashboard-neo/dist/assets/computer-device-network-wifi-router.svg-ZbvUMvW1.js +1 -0
- package/dashboard-neo/dist/assets/dist-CBT2ukx1.js +1 -0
- package/dashboard-neo/dist/assets/ecology-science-erlenmeyer-flask.svg-DntGEszJ.js +1 -0
- package/dashboard-neo/dist/assets/geist-cyrillic-wght-normal-CHSlOQsW.woff2 +0 -0
- package/dashboard-neo/dist/assets/geist-latin-ext-wght-normal-DMtmJ5ZE.woff2 +0 -0
- package/dashboard-neo/dist/assets/geist-latin-wght-normal-Dm3htQBi.woff2 +0 -0
- package/dashboard-neo/dist/assets/image-flash-lightning.svg-Y3Y6Te6J.js +1 -0
- package/dashboard-neo/dist/assets/image-picture-flower.svg-CAUJHFen.js +1 -0
- package/dashboard-neo/dist/assets/index-CCPRtotd.js +2355 -0
- package/dashboard-neo/dist/assets/index-Oo2D96Pi.css +1 -0
- package/dashboard-neo/dist/assets/interface-alert-exclamation-diamond.svg-d8x2YZNn.js +1 -0
- package/dashboard-neo/dist/assets/interface-alert-exclamation-triangle-warning.svg-BPj89imQ.js +1 -0
- package/dashboard-neo/dist/assets/interface-alert-information-circle.svg-B3_ZhHCU.js +1 -0
- package/dashboard-neo/dist/assets/interface-award-crown.svg-9QzG81ME.js +1 -0
- package/dashboard-neo/dist/assets/interface-bookmark-tag.svg-zyBnDZXV.js +1 -0
- package/dashboard-neo/dist/assets/interface-bookmark.svg-BokfxgR_.js +1 -0
- package/dashboard-neo/dist/assets/interface-calendar-date-one.svg-BG-gZa9b.js +1 -0
- package/dashboard-neo/dist/assets/interface-content-book-open-pages.svg-2LtAxgBC.js +1 -0
- package/dashboard-neo/dist/assets/interface-content-book-page.svg-Ck6AkesE.js +1 -0
- package/dashboard-neo/dist/assets/interface-content-file.svg-DTYoClw_.js +1 -0
- package/dashboard-neo/dist/assets/interface-content-folder.svg-DmEiVPx0.js +1 -0
- package/dashboard-neo/dist/assets/interface-copy-clipboard.svg-CFus7XXk.js +1 -0
- package/dashboard-neo/dist/assets/interface-edit-attachment.svg-ip-RcK7K.js +1 -0
- package/dashboard-neo/dist/assets/interface-edit-binocular.svg-Ci4HHNIj.js +1 -0
- package/dashboard-neo/dist/assets/interface-edit-magic-wand.svg-DGQaaElT.js +1 -0
- package/dashboard-neo/dist/assets/interface-edit-tool-paint-roller.svg-CvdyF2GE.js +1 -0
- package/dashboard-neo/dist/assets/interface-edit-tool-pencil.svg-PzM9gUeP.js +1 -0
- package/dashboard-neo/dist/assets/interface-favorite-award.svg-D4J0srBs.js +1 -0
- package/dashboard-neo/dist/assets/interface-favorite-flag.svg-BMfv0feo.js +1 -0
- package/dashboard-neo/dist/assets/interface-favorite-heart.svg-BOAdq0BP.js +1 -0
- package/dashboard-neo/dist/assets/interface-favorite-star.svg-BGYVoec6.js +1 -0
- package/dashboard-neo/dist/assets/interface-favorite-stars-sparkles.svg-DqvQo_6g.js +1 -0
- package/dashboard-neo/dist/assets/interface-hierarchy-flowchart.svg-GtL4lLOG.js +1 -0
- package/dashboard-neo/dist/assets/interface-home-house.svg-ByuIxm9E.js +1 -0
- package/dashboard-neo/dist/assets/interface-hyperlink.svg-C89foWq5.js +1 -0
- package/dashboard-neo/dist/assets/interface-lighting-brightness.svg-ChIQbj49.js +1 -0
- package/dashboard-neo/dist/assets/interface-lock-closed.svg-BUVt-tMS.js +1 -0
- package/dashboard-neo/dist/assets/interface-lock-open-unlock.svg-DiCIpC_I.js +1 -0
- package/dashboard-neo/dist/assets/interface-login-key.svg-BySvd_q6.js +1 -0
- package/dashboard-neo/dist/assets/interface-search.svg-DHAFxwgB.js +1 -0
- package/dashboard-neo/dist/assets/interface-setting-cog.svg-CZJNW0Qp.js +1 -0
- package/dashboard-neo/dist/assets/interface-share-megaphone-bullhorn.svg-Cf4N4ThN.js +1 -0
- package/dashboard-neo/dist/assets/interface-share-rocket.svg-DSexRWyi.js +1 -0
- package/dashboard-neo/dist/assets/interface-share-satellite.svg-DEhioy9C.js +1 -0
- package/dashboard-neo/dist/assets/interface-share-space-ship.svg-DJ2GwTST.js +1 -0
- package/dashboard-neo/dist/assets/interface-share.svg-AKwkJy5n.js +1 -0
- package/dashboard-neo/dist/assets/interface-signal-square.svg-BvwEOUAz.js +1 -0
- package/dashboard-neo/dist/assets/interface-time-clock-circle.svg-DKSsyftW.js +1 -0
- package/dashboard-neo/dist/assets/interface-time-hour-glass.svg-Beix5CQK.js +1 -0
- package/dashboard-neo/dist/assets/interface-users-multiple.svg-CCK9Jspv.js +1 -0
- package/dashboard-neo/dist/assets/interface-weather-moon.svg-jTm4hfXN.js +1 -0
- package/dashboard-neo/dist/assets/mail-chat-bubble-square.svg-BgP35Rk8.js +1 -0
- package/dashboard-neo/dist/assets/mail-send-email-paper-airplane.svg-C21cjIbh.js +1 -0
- package/dashboard-neo/dist/assets/mail-send-envelope.svg-DIAAOaDX.js +1 -0
- package/dashboard-neo/dist/assets/money-cashier-receipt.svg-v-s0fxDU.js +1 -0
- package/dashboard-neo/dist/assets/money-currency-dollar-pay.svg-rgB3LEAf.js +1 -0
- package/dashboard-neo/dist/assets/money-graph-arrow-increase.svg-CNbgQBLG.js +1 -0
- package/dashboard-neo/dist/assets/money-graph-bar-chart-increase.svg-NQo1v4xC.js +1 -0
- package/dashboard-neo/dist/assets/nature-ecology-leaf.svg-vGhsbpt0.js +1 -0
- package/dashboard-neo/dist/assets/phone-telephone.svg-DRQCKRxO.js +1 -0
- package/dashboard-neo/dist/assets/programming-bug.svg-B9Gbws6t.js +1 -0
- package/dashboard-neo/dist/assets/programming-cloud.svg-jmIeTucH.js +1 -0
- package/dashboard-neo/dist/assets/programming-computer-database-server.svg-MOV-SlSh.js +1 -0
- package/dashboard-neo/dist/assets/programming-computer-database.svg-ChO7iZyg.js +1 -0
- package/dashboard-neo/dist/assets/programming-module-four-layout.svg-DTARmxUz.js +1 -0
- package/dashboard-neo/dist/assets/programming-module-three.svg-6GRL_949.js +1 -0
- package/dashboard-neo/dist/assets/programming-module.svg-DxyUt2RE.js +1 -0
- package/dashboard-neo/dist/assets/programming-script-code.svg-D38umHb6.js +1 -0
- package/dashboard-neo/dist/assets/shopping-cart.svg--6vpSNLL.js +1 -0
- package/dashboard-neo/dist/assets/shopping-gift-present.svg-ChCol47c.js +1 -0
- package/dashboard-neo/dist/assets/shopping-shipping-box-parcel-package.svg-kFdGUfEt.js +1 -0
- package/dashboard-neo/dist/assets/tag-new-circle.svg-D1ph809h.js +1 -0
- package/dashboard-neo/dist/assets/travel-map-earth-globe.svg-meBGbHvi.js +1 -0
- package/dashboard-neo/dist/favicon.ico +0 -0
- package/dashboard-neo/dist/index.html +14 -0
- package/dashboard-neo/dist/manifest.json +25 -0
- package/dashboard-neo/dist/robots.txt +3 -0
- package/dist/index.cjs +2 -0
- package/package.json +11 -6
- package/.turbo/turbo-build.log +0 -20
- package/.turbo/turbo-test.log +0 -56
- package/CHANGELOG.md +0 -43
- package/src/auth/api-key.ts +0 -28
- package/src/compat/args.ts +0 -1
- package/src/compat/deprecation.ts +0 -35
- package/src/compat/session-path.ts +0 -19
- package/src/createApiMiddleware.ts +0 -184
- package/src/createApiServer.ts +0 -414
- package/src/dashboard/middleware.ts +0 -85
- package/src/docs/openapi.ts +0 -77
- package/src/docs/postman.ts +0 -42
- package/src/events/EventBridge.ts +0 -4
- package/src/events/EventBroadcaster.ts +0 -126
- package/src/execution/kernel.ts +0 -1
- package/src/health/HealthStore.ts +0 -242
- package/src/index.ts +0 -9
- package/src/invoke-client-method.ts +0 -1
- package/src/middleware/rate-limit.ts +0 -30
- package/src/monitoring/elastic.ts +0 -104
- package/src/routes/agent-discovery.ts +0 -150
- package/src/routes/debug.ts +0 -99
- package/src/routes/meta.ts +0 -512
- package/src/types.ts +0 -31
- package/test/mcp-integration.test.ts +0 -142
- package/tsconfig.json +0 -18
package/src/docs/openapi.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { HttpMethodDefinition } from '@open-wa/schema';
|
|
2
|
-
|
|
3
|
-
function schemaToOpenApi(schema: { toJSONSchema?: (params?: unknown) => unknown }) {
|
|
4
|
-
if (typeof schema?.toJSONSchema === 'function') {
|
|
5
|
-
return schema.toJSONSchema({ target: 'openapi-3.0' });
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return { type: 'object', additionalProperties: true };
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function buildQueryParameters(def: HttpMethodDefinition) {
|
|
12
|
-
const inputSchema = schemaToOpenApi(def.inputSchema) as {
|
|
13
|
-
properties?: Record<string, Record<string, unknown>>;
|
|
14
|
-
required?: string[];
|
|
15
|
-
};
|
|
16
|
-
const properties = inputSchema.properties ?? {};
|
|
17
|
-
const required = new Set(inputSchema.required ?? []);
|
|
18
|
-
|
|
19
|
-
return def.parameterOrder.map((name) => ({
|
|
20
|
-
name,
|
|
21
|
-
in: 'query',
|
|
22
|
-
required: required.has(name),
|
|
23
|
-
description: properties[name]?.description || `Argument: ${name}`,
|
|
24
|
-
schema: properties[name] || { type: 'string' },
|
|
25
|
-
}));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function createOpenApiDocument(
|
|
29
|
-
methodDefinitions: HttpMethodDefinition[],
|
|
30
|
-
options: { origin: string; basePath?: string; title?: string; version?: string }
|
|
31
|
-
) {
|
|
32
|
-
const paths = Object.fromEntries(
|
|
33
|
-
methodDefinitions.map((def) => [
|
|
34
|
-
def.path,
|
|
35
|
-
{
|
|
36
|
-
[def.httpMethod.toLowerCase()]: {
|
|
37
|
-
summary: def.description,
|
|
38
|
-
operationId: def.functionName,
|
|
39
|
-
tags: [def.namespace],
|
|
40
|
-
...(def.httpMethod === 'GET' || def.httpMethod === 'DELETE'
|
|
41
|
-
? { parameters: buildQueryParameters(def) }
|
|
42
|
-
: {
|
|
43
|
-
requestBody: {
|
|
44
|
-
required: def.parameterOrder.length > 0,
|
|
45
|
-
content: {
|
|
46
|
-
'application/json': {
|
|
47
|
-
schema: schemaToOpenApi(def.inputSchema),
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
}),
|
|
52
|
-
'x-openwa-aliases': def.routeSignatures.filter((signature) => signature !== `${def.httpMethod} ${def.path}`),
|
|
53
|
-
responses: {
|
|
54
|
-
'200': {
|
|
55
|
-
description: 'Successful response',
|
|
56
|
-
content: {
|
|
57
|
-
'application/json': {
|
|
58
|
-
schema: schemaToOpenApi(def.outputSchema),
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
])
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
openapi: '3.0.3',
|
|
70
|
-
info: {
|
|
71
|
-
title: options.title || 'open-wa Easy API',
|
|
72
|
-
version: options.version || '5.0.0',
|
|
73
|
-
},
|
|
74
|
-
servers: [{ url: options.origin }],
|
|
75
|
-
paths,
|
|
76
|
-
};
|
|
77
|
-
}
|
package/src/docs/postman.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { HttpMethodDefinition } from '@open-wa/schema';
|
|
2
|
-
|
|
3
|
-
export function createPostmanCollection(
|
|
4
|
-
methodDefinitions: HttpMethodDefinition[],
|
|
5
|
-
options: { origin: string; basePath?: string; name?: string }
|
|
6
|
-
) {
|
|
7
|
-
const basePath = options.basePath || '/api';
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
info: {
|
|
11
|
-
name: options.name || 'open-wa Easy API',
|
|
12
|
-
schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json',
|
|
13
|
-
},
|
|
14
|
-
variable: [
|
|
15
|
-
{
|
|
16
|
-
key: 'baseUrl',
|
|
17
|
-
value: `${options.origin}${basePath}`.replace(/\/api\/api$/, '/api'),
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
item: methodDefinitions.map((def) => ({
|
|
21
|
-
name: def.functionName,
|
|
22
|
-
request: {
|
|
23
|
-
method: 'POST',
|
|
24
|
-
header: [{ key: 'Content-Type', value: 'application/json' }],
|
|
25
|
-
url: {
|
|
26
|
-
raw: `{{baseUrl}}/${def.functionName}`,
|
|
27
|
-
host: ['{{baseUrl}}'],
|
|
28
|
-
path: [def.functionName],
|
|
29
|
-
},
|
|
30
|
-
body: {
|
|
31
|
-
mode: 'raw',
|
|
32
|
-
raw: JSON.stringify(
|
|
33
|
-
Object.fromEntries(def.parameterOrder.map((name) => [name, `<${name}>`])),
|
|
34
|
-
null,
|
|
35
|
-
2
|
|
36
|
-
),
|
|
37
|
-
},
|
|
38
|
-
description: def.description,
|
|
39
|
-
},
|
|
40
|
-
})),
|
|
41
|
-
};
|
|
42
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
export interface SseEventEnvelope {
|
|
2
|
-
id: string;
|
|
3
|
-
event: string;
|
|
4
|
-
payload: unknown;
|
|
5
|
-
ts: number;
|
|
6
|
-
sessionId: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface EventSubscriber {
|
|
10
|
-
topics: Set<string> | null;
|
|
11
|
-
push: (chunk: string) => void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface EventStreamOptions {
|
|
15
|
-
keepaliveMs?: number;
|
|
16
|
-
signal?: AbortSignal;
|
|
17
|
-
topics?: string[];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const DEFAULT_KEEPALIVE_MS = 20_000;
|
|
21
|
-
|
|
22
|
-
function normalizeTopics(topics?: string[]): Set<string> | null {
|
|
23
|
-
if (!topics || topics.length === 0 || topics.includes('*')) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return new Set(topics);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function formatEventFrame(envelope: SseEventEnvelope): string {
|
|
31
|
-
return `id: ${envelope.id}\nevent: ${envelope.event}\ndata: ${JSON.stringify(envelope)}\n\n`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export class EventBroadcaster {
|
|
35
|
-
private readonly encoder = new TextEncoder();
|
|
36
|
-
private readonly sessionId: string;
|
|
37
|
-
private nextEventId = 0;
|
|
38
|
-
private nextSubscriberId = 0;
|
|
39
|
-
private subscribers = new Map<number, EventSubscriber>();
|
|
40
|
-
|
|
41
|
-
constructor(sessionId?: string) {
|
|
42
|
-
this.sessionId = sessionId ?? '';
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public broadcast(event: string, payload: unknown): SseEventEnvelope {
|
|
46
|
-
const envelope: SseEventEnvelope = {
|
|
47
|
-
id: String(++this.nextEventId),
|
|
48
|
-
event,
|
|
49
|
-
payload,
|
|
50
|
-
ts: Date.now(),
|
|
51
|
-
sessionId: this.sessionId,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const frame = formatEventFrame(envelope);
|
|
55
|
-
|
|
56
|
-
for (const subscriber of this.subscribers.values()) {
|
|
57
|
-
if (subscriber.topics && !subscriber.topics.has(event)) {
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
subscriber.push(frame);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return envelope;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
public createStream(options: EventStreamOptions = {}): ReadableStream<Uint8Array> {
|
|
68
|
-
const topics = normalizeTopics(options.topics);
|
|
69
|
-
const keepaliveMs = options.keepaliveMs ?? DEFAULT_KEEPALIVE_MS;
|
|
70
|
-
let cleanup = () => {};
|
|
71
|
-
|
|
72
|
-
return new ReadableStream<Uint8Array>({
|
|
73
|
-
start: (controller) => {
|
|
74
|
-
const subscriberId = ++this.nextSubscriberId;
|
|
75
|
-
|
|
76
|
-
let closed = false;
|
|
77
|
-
|
|
78
|
-
const keepaliveTimer: ReturnType<typeof setInterval> = setInterval(() => {
|
|
79
|
-
push(':keepalive\n\n');
|
|
80
|
-
}, keepaliveMs);
|
|
81
|
-
|
|
82
|
-
cleanup = () => {
|
|
83
|
-
if (closed) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
closed = true;
|
|
88
|
-
this.subscribers.delete(subscriberId);
|
|
89
|
-
clearInterval(keepaliveTimer);
|
|
90
|
-
options.signal?.removeEventListener('abort', cleanup);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const push = (chunk: string) => {
|
|
94
|
-
if (closed) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
try {
|
|
99
|
-
controller.enqueue(this.encoder.encode(chunk));
|
|
100
|
-
} catch {
|
|
101
|
-
cleanup();
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
if (typeof keepaliveTimer.unref === 'function') {
|
|
106
|
-
keepaliveTimer.unref();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
this.subscribers.set(subscriberId, {
|
|
110
|
-
topics,
|
|
111
|
-
push,
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
options.signal?.addEventListener('abort', cleanup, { once: true });
|
|
115
|
-
push('retry: 3000\n\n');
|
|
116
|
-
},
|
|
117
|
-
cancel: () => {
|
|
118
|
-
cleanup();
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
public getSubscriberCount(): number {
|
|
124
|
-
return this.subscribers.size;
|
|
125
|
-
}
|
|
126
|
-
}
|
package/src/execution/kernel.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { executeCapability, type ExecutionContext, type ExecutionResult } from '@open-wa/mcp';
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HealthStore
|
|
3
|
-
*
|
|
4
|
-
* Lightweight in-memory accumulator for system health data.
|
|
5
|
-
* Captures launch timeline, patches, license info, and reconnection events
|
|
6
|
-
* from the core event emitter. Exposed via the `/health` REST endpoint
|
|
7
|
-
* so the dashboard can poll it without maintaining a persistent socket subscription.
|
|
8
|
-
*
|
|
9
|
-
* Memory-efficient: uses bounded arrays (max 100 reconnections) and
|
|
10
|
-
* only stores small summaries — no message payloads.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
const MAX_RECONNECTIONS = 100;
|
|
14
|
-
const MAX_TIMELINE_STEPS = 50;
|
|
15
|
-
|
|
16
|
-
export interface TimelineStep {
|
|
17
|
-
step: string;
|
|
18
|
-
status: 'done' | 'failed';
|
|
19
|
-
durationMs: number;
|
|
20
|
-
details?: Record<string, unknown>;
|
|
21
|
-
timestamp: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface PatchInfo {
|
|
25
|
-
patchId: string;
|
|
26
|
-
description: string;
|
|
27
|
-
required: boolean;
|
|
28
|
-
outcome: 'applied' | 'not_applicable' | 'failed';
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface LicenseInfo {
|
|
32
|
-
status: 'valid' | 'metadata_only' | 'missing' | 'invalid' | 'expired';
|
|
33
|
-
source: string;
|
|
34
|
-
keyType: string;
|
|
35
|
-
detail: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface ReconnectionEntry {
|
|
39
|
-
timestamp: number;
|
|
40
|
-
reason: string;
|
|
41
|
-
downtimeMs: number;
|
|
42
|
-
success: boolean;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface HealthSnapshot {
|
|
46
|
-
launchTimeline: TimelineStep[];
|
|
47
|
-
patches: PatchInfo[];
|
|
48
|
-
license: LicenseInfo | null;
|
|
49
|
-
reconnections: ReconnectionEntry[];
|
|
50
|
-
startedAt: number | null;
|
|
51
|
-
lastEventAt: number | null;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export class HealthStore {
|
|
55
|
-
private timeline: TimelineStep[] = [];
|
|
56
|
-
private patches: PatchInfo[] = [];
|
|
57
|
-
private license: LicenseInfo | null = null;
|
|
58
|
-
private reconnections: ReconnectionEntry[] = [];
|
|
59
|
-
private startedAt: number | null = null;
|
|
60
|
-
private lastEventAt: number | null = null;
|
|
61
|
-
|
|
62
|
-
// Step start times for computing durations
|
|
63
|
-
private stepStarts: Map<string, number> = new Map();
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Process an event from the core emitter.
|
|
67
|
-
* Call this from the onAny bridge with the event name and payload.
|
|
68
|
-
*/
|
|
69
|
-
processEvent(event: string, payload: unknown) {
|
|
70
|
-
const data = payload as Record<string, unknown> | undefined;
|
|
71
|
-
const ts = Date.now();
|
|
72
|
-
this.lastEventAt = ts;
|
|
73
|
-
|
|
74
|
-
// ── Launch timeline ──
|
|
75
|
-
if (event.startsWith('launch.') && event.endsWith('.before')) {
|
|
76
|
-
const step = event.replace('.before', '');
|
|
77
|
-
this.stepStarts.set(step, ts);
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (event.startsWith('launch.') && event.endsWith('.after')) {
|
|
82
|
-
const step = event.replace('.after', '');
|
|
83
|
-
const startTime = this.stepStarts.get(step);
|
|
84
|
-
const durationMs = startTime ? ts - startTime : 0;
|
|
85
|
-
this.stepStarts.delete(step);
|
|
86
|
-
|
|
87
|
-
const details = data as Record<string, unknown> | undefined;
|
|
88
|
-
const hasFailed = details?.success === false || details?.blockingFailure === true;
|
|
89
|
-
|
|
90
|
-
this.addTimelineStep({
|
|
91
|
-
step,
|
|
92
|
-
status: hasFailed ? 'failed' : 'done',
|
|
93
|
-
durationMs: (details?.durationMs as number) || durationMs,
|
|
94
|
-
details: details ? this.sanitizeDetails(details) : undefined,
|
|
95
|
-
timestamp: ts,
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
// Special: capture patch info from launch.patch.init.after
|
|
99
|
-
if (step === 'launch.patch.init') {
|
|
100
|
-
this.capturePatchInfo(details);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Special: capture license info from launch.license.preload.after or launch.license.check.after
|
|
104
|
-
if (step === 'launch.license.preload' || step === 'launch.license.check') {
|
|
105
|
-
this.captureLicenseInfo(details);
|
|
106
|
-
}
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// ── Direct step events (without .before/.after pattern) ──
|
|
111
|
-
if (event === 'launch.create.start') {
|
|
112
|
-
this.startedAt = ts;
|
|
113
|
-
this.addTimelineStep({
|
|
114
|
-
step: event,
|
|
115
|
-
status: 'done',
|
|
116
|
-
durationMs: 0,
|
|
117
|
-
details: data ? this.sanitizeDetails(data) : undefined,
|
|
118
|
-
timestamp: ts,
|
|
119
|
-
});
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (event === 'launch.create.ready') {
|
|
124
|
-
this.addTimelineStep({
|
|
125
|
-
step: event,
|
|
126
|
-
status: 'done',
|
|
127
|
-
durationMs: 0,
|
|
128
|
-
details: data ? this.sanitizeDetails(data) : undefined,
|
|
129
|
-
timestamp: ts,
|
|
130
|
-
});
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// ── Reconnection tracking ──
|
|
135
|
-
if (event === 'session.connection.disconnected') {
|
|
136
|
-
// We'll start tracking a disconnect; only add if we later get a reconnect
|
|
137
|
-
this.reconnections.push({
|
|
138
|
-
timestamp: Math.floor(ts / 1000),
|
|
139
|
-
reason: (data?.reason as string) || 'unknown',
|
|
140
|
-
downtimeMs: 0,
|
|
141
|
-
success: false,
|
|
142
|
-
});
|
|
143
|
-
if (this.reconnections.length > MAX_RECONNECTIONS) {
|
|
144
|
-
this.reconnections.shift();
|
|
145
|
-
}
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (event === 'session.connection.reconnected') {
|
|
150
|
-
// Find the last disconnect and mark it as successful
|
|
151
|
-
const last = this.reconnections[this.reconnections.length - 1];
|
|
152
|
-
if (last && !last.success) {
|
|
153
|
-
last.success = true;
|
|
154
|
-
last.downtimeMs = (data?.downtimeMs as number) || 0;
|
|
155
|
-
} else {
|
|
156
|
-
this.reconnections.push({
|
|
157
|
-
timestamp: Math.floor(ts / 1000),
|
|
158
|
-
reason: 'reconnected',
|
|
159
|
-
downtimeMs: (data?.downtimeMs as number) || 0,
|
|
160
|
-
success: true,
|
|
161
|
-
});
|
|
162
|
-
if (this.reconnections.length > MAX_RECONNECTIONS) {
|
|
163
|
-
this.reconnections.shift();
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// ── Session state changes ──
|
|
170
|
-
if (event === 'session.state.changed') {
|
|
171
|
-
this.addTimelineStep({
|
|
172
|
-
step: event,
|
|
173
|
-
status: 'done',
|
|
174
|
-
durationMs: 0,
|
|
175
|
-
details: data ? this.sanitizeDetails(data) : undefined,
|
|
176
|
-
timestamp: ts,
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Get a snapshot of all accumulated health data.
|
|
183
|
-
* This is what gets returned by the /health endpoint.
|
|
184
|
-
*/
|
|
185
|
-
getSnapshot(): HealthSnapshot {
|
|
186
|
-
return {
|
|
187
|
-
launchTimeline: [...this.timeline],
|
|
188
|
-
patches: [...this.patches],
|
|
189
|
-
license: this.license ? { ...this.license } : null,
|
|
190
|
-
reconnections: [...this.reconnections],
|
|
191
|
-
startedAt: this.startedAt,
|
|
192
|
-
lastEventAt: this.lastEventAt,
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
private addTimelineStep(step: TimelineStep) {
|
|
197
|
-
this.timeline.push(step);
|
|
198
|
-
if (this.timeline.length > MAX_TIMELINE_STEPS) {
|
|
199
|
-
this.timeline.shift();
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
private capturePatchInfo(details?: Record<string, unknown>) {
|
|
204
|
-
if (!details) return;
|
|
205
|
-
const applied = (details.applied as string[]) || [];
|
|
206
|
-
const available = (details.available as string[]) || applied;
|
|
207
|
-
const outcome = details.outcome as string;
|
|
208
|
-
|
|
209
|
-
this.patches = available.map((id) => ({
|
|
210
|
-
patchId: id,
|
|
211
|
-
description: `Patch ${id}`,
|
|
212
|
-
required: true,
|
|
213
|
-
outcome: applied.includes(id) ? 'applied' as const : (outcome === 'none' ? 'not_applicable' as const : 'failed' as const),
|
|
214
|
-
}));
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
private captureLicenseInfo(details?: Record<string, unknown>) {
|
|
218
|
-
if (!details) return;
|
|
219
|
-
this.license = {
|
|
220
|
-
status: (details.status as LicenseInfo['status']) || 'missing',
|
|
221
|
-
source: (details.source as string) || 'unknown',
|
|
222
|
-
keyType: (details.payloadSource as string) || 'unknown',
|
|
223
|
-
detail: (details.detail as string) || `License ${details.status || 'check complete'}`,
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/** Remove large/noisy fields from details to keep memory lean */
|
|
228
|
-
private sanitizeDetails(data: Record<string, unknown>): Record<string, unknown> {
|
|
229
|
-
const clean: Record<string, unknown> = {};
|
|
230
|
-
for (const [key, val] of Object.entries(data)) {
|
|
231
|
-
// Skip internal fields
|
|
232
|
-
if (key === 'correlationId' || key === 'ts' || key === 'step') continue;
|
|
233
|
-
// Skip large arrays/objects
|
|
234
|
-
if (Array.isArray(val) && val.length > 10) {
|
|
235
|
-
clean[key] = `[${val.length} items]`;
|
|
236
|
-
continue;
|
|
237
|
-
}
|
|
238
|
-
clean[key] = val;
|
|
239
|
-
}
|
|
240
|
-
return clean;
|
|
241
|
-
}
|
|
242
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { ApiServer, createApiServer } from './createApiServer';
|
|
2
|
-
export { createApiMiddleware } from './createApiMiddleware';
|
|
3
|
-
export { apiKeyMiddleware } from './auth/api-key';
|
|
4
|
-
export { rateLimitMiddleware } from './middleware/rate-limit';
|
|
5
|
-
export { type EventBridge } from './events/EventBridge';
|
|
6
|
-
export { EventBroadcaster, type EventStreamOptions, type SseEventEnvelope } from './events/EventBroadcaster';
|
|
7
|
-
export { invokeClientMethod, type ClientMethodDefinitionLike } from './invoke-client-method';
|
|
8
|
-
export { ElasticEmitter, type ElasticConfig, type ElasticDoc } from './monitoring/elastic';
|
|
9
|
-
export type { ApiMiddlewareOptions, ApiServerOptions, ClientMethodMap, ClientSource } from './types';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { invokeClientMethod, type ClientMethodDefinitionLike } from '@open-wa/mcp';
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Context, Next } from 'hono';
|
|
2
|
-
|
|
3
|
-
const requests = new Map<string, number[]>();
|
|
4
|
-
|
|
5
|
-
function getRequestKey(c: Context): string {
|
|
6
|
-
const forwarded = c.req.header('x-forwarded-for');
|
|
7
|
-
|
|
8
|
-
if (forwarded) {
|
|
9
|
-
return forwarded.split(',')[0].trim();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return c.req.header('x-real-ip') || 'unknown';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function rateLimitMiddleware(maxRequests = 100, windowMs = 60000) {
|
|
16
|
-
return async (c: Context, next: Next) => {
|
|
17
|
-
const requestKey = getRequestKey(c);
|
|
18
|
-
const now = Date.now();
|
|
19
|
-
const recentRequests = (requests.get(requestKey) || []).filter((time) => now - time < windowMs);
|
|
20
|
-
|
|
21
|
-
if (recentRequests.length >= maxRequests) {
|
|
22
|
-
return c.json({ error: 'Too Many Requests', details: 'Rate limit exceeded' }, 429);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
recentRequests.push(now);
|
|
26
|
-
requests.set(requestKey, recentRequests);
|
|
27
|
-
|
|
28
|
-
return await next();
|
|
29
|
-
};
|
|
30
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
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
|
-
}
|