@shepai/cli 1.163.0-pr511.366ece8 → 1.163.0-pr512.9a94785
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/apis/json-schema/MessagingCommand.yaml +28 -0
- package/apis/json-schema/MessagingCommandType.yaml +14 -0
- package/apis/json-schema/MessagingConfig.yaml +34 -0
- package/apis/json-schema/MessagingFrameType.yaml +8 -0
- package/apis/json-schema/MessagingNotification.yaml +22 -0
- package/apis/json-schema/MessagingPlatform.yaml +7 -0
- package/apis/json-schema/MessagingPlatformConfig.yaml +19 -0
- package/apis/json-schema/Settings.yaml +3 -0
- package/dist/packages/core/src/application/ports/output/services/messaging-service.interface.d.ts +34 -0
- package/dist/packages/core/src/application/ports/output/services/messaging-service.interface.d.ts.map +1 -0
- package/dist/packages/core/src/application/ports/output/services/messaging-service.interface.js +12 -0
- package/dist/packages/core/src/domain/generated/output.d.ts +120 -0
- package/dist/packages/core/src/domain/generated/output.d.ts.map +1 -1
- package/dist/packages/core/src/domain/generated/output.js +23 -0
- package/dist/packages/core/src/infrastructure/di/container.d.ts.map +1 -1
- package/dist/packages/core/src/infrastructure/di/container.js +59 -0
- package/dist/packages/core/src/infrastructure/services/messaging/chat-relay.d.ts +43 -0
- package/dist/packages/core/src/infrastructure/services/messaging/chat-relay.d.ts.map +1 -0
- package/dist/packages/core/src/infrastructure/services/messaging/chat-relay.js +93 -0
- package/dist/packages/core/src/infrastructure/services/messaging/command-executor.d.ts +53 -0
- package/dist/packages/core/src/infrastructure/services/messaging/command-executor.d.ts.map +1 -0
- package/dist/packages/core/src/infrastructure/services/messaging/command-executor.js +200 -0
- package/dist/packages/core/src/infrastructure/services/messaging/content-sanitizer.d.ts +23 -0
- package/dist/packages/core/src/infrastructure/services/messaging/content-sanitizer.d.ts.map +1 -0
- package/dist/packages/core/src/infrastructure/services/messaging/content-sanitizer.js +39 -0
- package/dist/packages/core/src/infrastructure/services/messaging/messaging-tunnel.adapter.d.ts +50 -0
- package/dist/packages/core/src/infrastructure/services/messaging/messaging-tunnel.adapter.d.ts.map +1 -0
- package/dist/packages/core/src/infrastructure/services/messaging/messaging-tunnel.adapter.js +140 -0
- package/dist/packages/core/src/infrastructure/services/messaging/messaging.service.d.ts +58 -0
- package/dist/packages/core/src/infrastructure/services/messaging/messaging.service.d.ts.map +1 -0
- package/dist/packages/core/src/infrastructure/services/messaging/messaging.service.js +104 -0
- package/dist/packages/core/src/infrastructure/services/messaging/notification-emitter.d.ts +33 -0
- package/dist/packages/core/src/infrastructure/services/messaging/notification-emitter.d.ts.map +1 -0
- package/dist/packages/core/src/infrastructure/services/messaging/notification-emitter.js +79 -0
- package/dist/src/presentation/cli/commands/_serve.command.d.ts.map +1 -1
- package/dist/src/presentation/cli/commands/_serve.command.js +6 -0
- package/dist/src/presentation/cli/commands/settings/index.d.ts.map +1 -1
- package/dist/src/presentation/cli/commands/settings/index.js +3 -1
- package/dist/src/presentation/cli/commands/settings/messaging.command.d.ts +17 -0
- package/dist/src/presentation/cli/commands/settings/messaging.command.d.ts.map +1 -0
- package/dist/src/presentation/cli/commands/settings/messaging.command.js +161 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/web/.next/BUILD_ID +1 -1
- package/web/.next/build-manifest.json +2 -2
- package/web/.next/fallback-build-manifest.json +2 -2
- package/web/.next/prerender-manifest.json +3 -3
- package/web/.next/required-server-files.js +1 -1
- package/web/.next/required-server-files.json +1 -1
- package/web/.next/server/app/(dashboard)/@drawer/adopt/page/server-reference-manifest.json +29 -29
- package/web/.next/server/app/(dashboard)/@drawer/adopt/page.js.nft.json +1 -1
- package/web/.next/server/app/(dashboard)/@drawer/adopt/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/(dashboard)/@drawer/chat/page/server-reference-manifest.json +27 -27
- package/web/.next/server/app/(dashboard)/@drawer/chat/page.js.nft.json +1 -1
- package/web/.next/server/app/(dashboard)/@drawer/chat/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/(dashboard)/@drawer/create/page/server-reference-manifest.json +30 -30
- package/web/.next/server/app/(dashboard)/@drawer/create/page.js.nft.json +1 -1
- package/web/.next/server/app/(dashboard)/@drawer/create/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/(dashboard)/@drawer/feature/[featureId]/[tab]/page/server-reference-manifest.json +37 -37
- package/web/.next/server/app/(dashboard)/@drawer/feature/[featureId]/[tab]/page.js.nft.json +1 -1
- package/web/.next/server/app/(dashboard)/@drawer/feature/[featureId]/[tab]/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/(dashboard)/@drawer/feature/[featureId]/page/server-reference-manifest.json +37 -37
- package/web/.next/server/app/(dashboard)/@drawer/feature/[featureId]/page.js.nft.json +1 -1
- package/web/.next/server/app/(dashboard)/@drawer/feature/[featureId]/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/(dashboard)/@drawer/repository/[repositoryId]/[tab]/page/server-reference-manifest.json +27 -27
- package/web/.next/server/app/(dashboard)/@drawer/repository/[repositoryId]/[tab]/page.js.nft.json +1 -1
- package/web/.next/server/app/(dashboard)/@drawer/repository/[repositoryId]/[tab]/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/(dashboard)/@drawer/repository/[repositoryId]/page/server-reference-manifest.json +27 -27
- package/web/.next/server/app/(dashboard)/@drawer/repository/[repositoryId]/page.js.nft.json +1 -1
- package/web/.next/server/app/(dashboard)/@drawer/repository/[repositoryId]/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/(dashboard)/chat/page/server-reference-manifest.json +27 -27
- package/web/.next/server/app/(dashboard)/chat/page.js.nft.json +1 -1
- package/web/.next/server/app/(dashboard)/chat/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/(dashboard)/create/page/server-reference-manifest.json +30 -30
- package/web/.next/server/app/(dashboard)/create/page.js.nft.json +1 -1
- package/web/.next/server/app/(dashboard)/create/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/(dashboard)/feature/[featureId]/[tab]/page/server-reference-manifest.json +37 -37
- package/web/.next/server/app/(dashboard)/feature/[featureId]/[tab]/page.js.nft.json +1 -1
- package/web/.next/server/app/(dashboard)/feature/[featureId]/[tab]/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/(dashboard)/feature/[featureId]/page/server-reference-manifest.json +37 -37
- package/web/.next/server/app/(dashboard)/feature/[featureId]/page.js.nft.json +1 -1
- package/web/.next/server/app/(dashboard)/feature/[featureId]/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/(dashboard)/page/server-reference-manifest.json +27 -27
- package/web/.next/server/app/(dashboard)/page.js.nft.json +1 -1
- package/web/.next/server/app/(dashboard)/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/(dashboard)/repository/[repositoryId]/[tab]/page/server-reference-manifest.json +27 -27
- package/web/.next/server/app/(dashboard)/repository/[repositoryId]/[tab]/page.js.nft.json +1 -1
- package/web/.next/server/app/(dashboard)/repository/[repositoryId]/[tab]/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/(dashboard)/repository/[repositoryId]/page/server-reference-manifest.json +27 -27
- package/web/.next/server/app/(dashboard)/repository/[repositoryId]/page.js.nft.json +1 -1
- package/web/.next/server/app/(dashboard)/repository/[repositoryId]/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/_global-error.html +2 -2
- package/web/.next/server/app/_global-error.rsc +1 -1
- package/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/web/.next/server/app/_not-found/page/server-reference-manifest.json +6 -6
- package/web/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/settings/page/server-reference-manifest.json +9 -9
- package/web/.next/server/app/settings/page.js.nft.json +1 -1
- package/web/.next/server/app/settings/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/skills/page/server-reference-manifest.json +11 -11
- package/web/.next/server/app/skills/page.js.nft.json +1 -1
- package/web/.next/server/app/skills/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/tools/page/server-reference-manifest.json +11 -11
- package/web/.next/server/app/tools/page.js.nft.json +1 -1
- package/web/.next/server/app/tools/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/version/page/server-reference-manifest.json +6 -6
- package/web/.next/server/app/version/page.js.nft.json +1 -1
- package/web/.next/server/app/version/page_client-reference-manifest.js +1 -1
- package/web/.next/server/chunks/[root-of-the-server]__a402b567._.js +1 -1
- package/web/.next/server/chunks/[root-of-the-server]__beda892a._.js +1 -1
- package/web/.next/server/chunks/[root-of-the-server]__beda892a._.js.map +1 -1
- package/web/.next/server/chunks/[root-of-the-server]__cd67a84c._.js +1 -1
- package/web/.next/server/chunks/[root-of-the-server]__cd67a84c._.js.map +1 -1
- package/web/.next/server/chunks/ssr/744ca_web_components_common_control-center-drawer_create-drawer-client_tsx_5e26fc0a._.js +1 -1
- package/web/.next/server/chunks/ssr/744ca_web_components_common_control-center-drawer_create-drawer-client_tsx_5e26fc0a._.js.map +1 -1
- package/web/.next/server/chunks/ssr/744ca_web_components_common_control-center-drawer_feature-drawer-client_tsx_e9755fc8._.js +2 -2
- package/web/.next/server/chunks/ssr/744ca_web_components_common_control-center-drawer_feature-drawer-client_tsx_e9755fc8._.js.map +1 -1
- package/web/.next/server/chunks/ssr/[root-of-the-server]__1abe77bb._.js +2 -2
- package/web/.next/server/chunks/ssr/[root-of-the-server]__1abe77bb._.js.map +1 -1
- package/web/.next/server/chunks/ssr/[root-of-the-server]__1f389e5d._.js +1 -1
- package/web/.next/server/chunks/ssr/[root-of-the-server]__1f389e5d._.js.map +1 -1
- package/web/.next/server/chunks/ssr/[root-of-the-server]__357d99f9._.js +1 -1
- package/web/.next/server/chunks/ssr/[root-of-the-server]__563e4faf._.js +1 -1
- package/web/.next/server/chunks/ssr/[root-of-the-server]__563e4faf._.js.map +1 -1
- package/web/.next/server/chunks/ssr/[root-of-the-server]__7562afc6._.js +2 -2
- package/web/.next/server/chunks/ssr/[root-of-the-server]__7562afc6._.js.map +1 -1
- package/web/.next/server/chunks/ssr/[root-of-the-server]__821a11c1._.js +1 -1
- package/web/.next/server/chunks/ssr/[root-of-the-server]__821a11c1._.js.map +1 -1
- package/web/.next/server/chunks/ssr/[root-of-the-server]__8b0aac03._.js +1 -1
- package/web/.next/server/chunks/ssr/[root-of-the-server]__98740ee4._.js +1 -1
- package/web/.next/server/chunks/ssr/[root-of-the-server]__98740ee4._.js.map +1 -1
- package/web/.next/server/chunks/ssr/[root-of-the-server]__b7b96453._.js +1 -1
- package/web/.next/server/chunks/ssr/[root-of-the-server]__b7b96453._.js.map +1 -1
- package/web/.next/server/chunks/ssr/[root-of-the-server]__ba9f9e11._.js +1 -1
- package/web/.next/server/chunks/ssr/[root-of-the-server]__ba9f9e11._.js.map +1 -1
- package/web/.next/server/chunks/ssr/[root-of-the-server]__e5ceba65._.js +1 -1
- package/web/.next/server/chunks/ssr/[root-of-the-server]__e5ceba65._.js.map +1 -1
- package/web/.next/server/chunks/ssr/_05c23ad9._.js +1 -1
- package/web/.next/server/chunks/ssr/_05c23ad9._.js.map +1 -1
- package/web/.next/server/chunks/ssr/_0727935d._.js +1 -1
- package/web/.next/server/chunks/ssr/_0727935d._.js.map +1 -1
- package/web/.next/server/chunks/ssr/_075fae20._.js +1 -1
- package/web/.next/server/chunks/ssr/_075fae20._.js.map +1 -1
- package/web/.next/server/chunks/ssr/_0dc06d07._.js.map +1 -1
- package/web/.next/server/chunks/ssr/_125c55af._.js +1 -1
- package/web/.next/server/chunks/ssr/_125c55af._.js.map +1 -1
- package/web/.next/server/chunks/ssr/_16eb4fec._.js +1 -1
- package/web/.next/server/chunks/ssr/_16eb4fec._.js.map +1 -1
- package/web/.next/server/chunks/ssr/{_ed99826e._.js → _17c3344c._.js} +2 -2
- package/web/.next/server/chunks/ssr/{_ed99826e._.js.map → _17c3344c._.js.map} +1 -1
- package/web/.next/server/chunks/ssr/_22e00a14._.js +1 -1
- package/web/.next/server/chunks/ssr/_22e00a14._.js.map +1 -1
- package/web/.next/server/chunks/ssr/{_fb06d580._.js → _30ae6384._.js} +2 -2
- package/web/.next/server/chunks/ssr/{_fb06d580._.js.map → _30ae6384._.js.map} +1 -1
- package/web/.next/server/chunks/ssr/_5119a3df._.js.map +1 -1
- package/web/.next/server/chunks/ssr/_56b9d60f._.js +1 -1
- package/web/.next/server/chunks/ssr/_56b9d60f._.js.map +1 -1
- package/web/.next/server/chunks/ssr/_628621c7._.js +1 -1
- package/web/.next/server/chunks/ssr/_628621c7._.js.map +1 -1
- package/web/.next/server/chunks/ssr/{_18ca0899._.js → _8dcb8b58._.js} +2 -2
- package/web/.next/server/chunks/ssr/{_18ca0899._.js.map → _8dcb8b58._.js.map} +1 -1
- package/web/.next/server/chunks/ssr/_9412b27f._.js +1 -1
- package/web/.next/server/chunks/ssr/_9412b27f._.js.map +1 -1
- package/web/.next/server/chunks/ssr/_a5a5901d._.js +1 -1
- package/web/.next/server/chunks/ssr/_a5a5901d._.js.map +1 -1
- package/web/.next/server/chunks/ssr/_ac4a3873._.js +1 -1
- package/web/.next/server/chunks/ssr/_c3f595c6._.js +1 -1
- package/web/.next/server/chunks/ssr/_c3f595c6._.js.map +1 -1
- package/web/.next/server/chunks/ssr/_f1ba9be6._.js +2 -2
- package/web/.next/server/chunks/ssr/_f1ba9be6._.js.map +1 -1
- package/web/.next/server/chunks/ssr/_f33cd07e._.js +2 -2
- package/web/.next/server/chunks/ssr/_f33cd07e._.js.map +1 -1
- package/web/.next/server/chunks/ssr/_f8b45233._.js +1 -1
- package/web/.next/server/chunks/ssr/_f8b45233._.js.map +1 -1
- package/web/.next/server/chunks/ssr/b1a17_presentation_web_components_features_settings_settings-page-client_tsx_6ed9d5f8._.js +1 -1
- package/web/.next/server/chunks/ssr/b1a17_presentation_web_components_features_settings_settings-page-client_tsx_6ed9d5f8._.js.map +1 -1
- package/web/.next/server/chunks/ssr/src_presentation_web_app_actions_open-ide_ts_baaca5d5._.js +1 -1
- package/web/.next/server/chunks/ssr/src_presentation_web_components_895e5bfa._.js +1 -1
- package/web/.next/server/chunks/ssr/src_presentation_web_components_895e5bfa._.js.map +1 -1
- package/web/.next/server/chunks/ssr/src_presentation_web_components_features_control-center_7ac3562e._.js +1 -1
- package/web/.next/server/chunks/ssr/src_presentation_web_components_features_control-center_7ac3562e._.js.map +1 -1
- package/web/.next/server/pages/500.html +2 -2
- package/web/.next/server/server-reference-manifest.js +1 -1
- package/web/.next/server/server-reference-manifest.json +46 -46
- package/web/.next/static/chunks/{d6ddde714cdc2efe.js → 0c18b8915d939a76.js} +1 -1
- package/web/.next/static/chunks/{5044bc870aa7b79f.js → 1d2e6f6e7aa59ee7.js} +2 -2
- package/web/.next/static/chunks/{e9310c34cd44a08e.js → 2354d39c63978576.js} +1 -1
- package/web/.next/static/chunks/{21acc5ea573082b6.js → 3deefc76ea55047c.js} +1 -1
- package/web/.next/static/chunks/{db14388056f49e6b.js → 47477ed4c5871747.js} +1 -1
- package/web/.next/static/chunks/{a3ee11f191a73592.js → 4b7456781c9b4ab5.js} +1 -1
- package/web/.next/static/chunks/{dbdd5bfd2c6dd329.js → 63cfaba0d8d962da.js} +1 -1
- package/web/.next/static/chunks/{8b37e6de79a3dd77.js → 74db65fa7bfb80bd.js} +1 -1
- package/web/.next/static/chunks/{bb103de647751269.js → a15e9c4b7af67476.js} +1 -1
- package/web/.next/static/chunks/{0597b8d09919ee4b.js → a3bedc7a2649d1e0.js} +1 -1
- package/web/.next/static/chunks/{e80f10ee969afbe3.js → ac36b3666208b529.js} +1 -1
- package/web/.next/static/chunks/{74828589e4309603.js → d5d91d64bdf8d21c.js} +2 -2
- package/web/.next/static/chunks/{20b904475fa8f8ee.js → dcd124591ee6580d.js} +1 -1
- package/web/.next/static/chunks/{824eb4327f11de2f.js → e9814323885535c3.js} +1 -1
- package/web/.next/static/chunks/{671241415d61f5cb.js → ee2e25620227d46a.js} +3 -3
- package/web/.next/static/chunks/{582a824f9edfff4b.js → f0f48245b38cd4fb.js} +1 -1
- /package/web/.next/static/{Zt9STnUCkSmOuts-wOHt7 → mCo4eb-j7a9M_HjR4zGyS}/_buildManifest.js +0 -0
- /package/web/.next/static/{Zt9STnUCkSmOuts-wOHt7 → mCo4eb-j7a9M_HjR4zGyS}/_clientMiddlewareManifest.json +0 -0
- /package/web/.next/static/{Zt9STnUCkSmOuts-wOHt7 → mCo4eb-j7a9M_HjR4zGyS}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Messaging Chat Relay
|
|
3
|
+
*
|
|
4
|
+
* Bridges messaging app chat ↔ Shep interactive agent sessions.
|
|
5
|
+
* When a user enters "chat mode" via /chat <feature_id>, their messages
|
|
6
|
+
* are relayed to the agent and agent responses are batched and sent back
|
|
7
|
+
* through the tunnel.
|
|
8
|
+
*
|
|
9
|
+
* Output batching: agent streaming output is buffered and flushed every
|
|
10
|
+
* N milliseconds (default 3s) to avoid flooding messaging platforms.
|
|
11
|
+
* Only one active relay per user at a time.
|
|
12
|
+
*/
|
|
13
|
+
import { sanitizeForMessaging } from './content-sanitizer.js';
|
|
14
|
+
const DEFAULT_BUFFER_INTERVAL_MS = 3_000;
|
|
15
|
+
/**
|
|
16
|
+
* Manages the bidirectional chat relay between messaging apps
|
|
17
|
+
* and Shep interactive agent sessions.
|
|
18
|
+
*/
|
|
19
|
+
export class MessagingChatRelay {
|
|
20
|
+
tunnelAdapter;
|
|
21
|
+
bufferIntervalMs;
|
|
22
|
+
activeRelay = null;
|
|
23
|
+
buffer = '';
|
|
24
|
+
bufferTimer = null;
|
|
25
|
+
constructor(tunnelAdapter, bufferIntervalMs = DEFAULT_BUFFER_INTERVAL_MS) {
|
|
26
|
+
this.tunnelAdapter = tunnelAdapter;
|
|
27
|
+
this.bufferIntervalMs = bufferIntervalMs;
|
|
28
|
+
}
|
|
29
|
+
/** Start a chat relay for a specific feature */
|
|
30
|
+
startRelay(featureId, chatId, platform) {
|
|
31
|
+
// Stop existing relay if any
|
|
32
|
+
if (this.activeRelay) {
|
|
33
|
+
this.flushBuffer();
|
|
34
|
+
}
|
|
35
|
+
this.activeRelay = { featureId, chatId, platform };
|
|
36
|
+
return `Chat relay started for feature #${featureId}. Send messages here to talk to the agent. /end to stop.`;
|
|
37
|
+
}
|
|
38
|
+
/** End the active chat relay */
|
|
39
|
+
endRelay() {
|
|
40
|
+
if (!this.activeRelay) {
|
|
41
|
+
return 'No active chat relay.';
|
|
42
|
+
}
|
|
43
|
+
this.flushBuffer();
|
|
44
|
+
const fid = this.activeRelay.featureId;
|
|
45
|
+
this.activeRelay = null;
|
|
46
|
+
return `Chat relay ended for feature #${fid}.`;
|
|
47
|
+
}
|
|
48
|
+
/** Check if there is an active relay */
|
|
49
|
+
hasActiveRelay() {
|
|
50
|
+
return this.activeRelay !== null;
|
|
51
|
+
}
|
|
52
|
+
/** Get the active relay's feature ID */
|
|
53
|
+
getActiveFeatureId() {
|
|
54
|
+
return this.activeRelay?.featureId ?? null;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Buffer an agent response chunk and schedule a flush.
|
|
58
|
+
* Called when the agent produces output during a chat relay.
|
|
59
|
+
*/
|
|
60
|
+
bufferAgentOutput(delta) {
|
|
61
|
+
if (!this.activeRelay)
|
|
62
|
+
return;
|
|
63
|
+
this.buffer += delta;
|
|
64
|
+
if (!this.bufferTimer) {
|
|
65
|
+
this.bufferTimer = setTimeout(() => {
|
|
66
|
+
this.flushBuffer();
|
|
67
|
+
}, this.bufferIntervalMs);
|
|
68
|
+
this.bufferTimer.unref();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** Flush any buffered output immediately (e.g., on stream completion) */
|
|
72
|
+
flushBuffer() {
|
|
73
|
+
if (this.buffer && this.activeRelay) {
|
|
74
|
+
const notification = {
|
|
75
|
+
event: 'chat.response',
|
|
76
|
+
featureId: this.activeRelay.featureId,
|
|
77
|
+
title: '',
|
|
78
|
+
message: sanitizeForMessaging(this.buffer),
|
|
79
|
+
};
|
|
80
|
+
this.tunnelAdapter.sendNotification(notification);
|
|
81
|
+
this.buffer = '';
|
|
82
|
+
}
|
|
83
|
+
if (this.bufferTimer) {
|
|
84
|
+
clearTimeout(this.bufferTimer);
|
|
85
|
+
this.bufferTimer = null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** Stop the relay and clean up all resources */
|
|
89
|
+
stop() {
|
|
90
|
+
this.flushBuffer();
|
|
91
|
+
this.activeRelay = null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Messaging Command Executor
|
|
3
|
+
*
|
|
4
|
+
* Maps inbound MessagingCommand payloads from the Gateway tunnel
|
|
5
|
+
* to existing Shep use case invocations. This is the bridge between
|
|
6
|
+
* external messaging commands and the application layer.
|
|
7
|
+
*
|
|
8
|
+
* All commands are mapped to existing use cases — no new business logic
|
|
9
|
+
* is introduced here. The executor is a thin translation layer.
|
|
10
|
+
*
|
|
11
|
+
* Feature ID resolution: messaging commands use short IDs (first 8 chars
|
|
12
|
+
* of the UUID). The ShowFeatureUseCase and ResumeFeatureUseCase support
|
|
13
|
+
* prefix matching via findByIdPrefix. For approve/reject/stop, we resolve
|
|
14
|
+
* the feature first, then use its agentRunId.
|
|
15
|
+
*/
|
|
16
|
+
import type { MessagingCommand } from '../../../domain/generated/output.js';
|
|
17
|
+
import type { IFeatureRepository } from '../../../application/ports/output/repositories/feature-repository.interface.js';
|
|
18
|
+
import type { ListFeaturesUseCase } from '../../../application/use-cases/features/list-features.use-case.js';
|
|
19
|
+
import type { ShowFeatureUseCase } from '../../../application/use-cases/features/show-feature.use-case.js';
|
|
20
|
+
import type { CreateFeatureUseCase } from '../../../application/use-cases/features/create/create-feature.use-case.js';
|
|
21
|
+
import type { ApproveAgentRunUseCase } from '../../../application/use-cases/agents/approve-agent-run.use-case.js';
|
|
22
|
+
import type { RejectAgentRunUseCase } from '../../../application/use-cases/agents/reject-agent-run.use-case.js';
|
|
23
|
+
import type { StopAgentRunUseCase } from '../../../application/use-cases/agents/stop-agent-run.use-case.js';
|
|
24
|
+
import type { ResumeFeatureUseCase } from '../../../application/use-cases/features/resume-feature.use-case.js';
|
|
25
|
+
import type { ListRepositoriesUseCase } from '../../../application/use-cases/repositories/list-repositories.use-case.js';
|
|
26
|
+
/**
|
|
27
|
+
* Execute messaging commands by delegating to existing use cases.
|
|
28
|
+
*/
|
|
29
|
+
export declare class MessagingCommandExecutor {
|
|
30
|
+
private readonly featureRepo;
|
|
31
|
+
private readonly createFeature;
|
|
32
|
+
private readonly approveAgentRun;
|
|
33
|
+
private readonly rejectAgentRun;
|
|
34
|
+
private readonly stopAgentRun;
|
|
35
|
+
private readonly resumeFeature;
|
|
36
|
+
private readonly listFeatures;
|
|
37
|
+
private readonly showFeature;
|
|
38
|
+
private readonly listRepositories;
|
|
39
|
+
constructor(featureRepo: IFeatureRepository, createFeature: CreateFeatureUseCase, approveAgentRun: ApproveAgentRunUseCase, rejectAgentRun: RejectAgentRunUseCase, stopAgentRun: StopAgentRunUseCase, resumeFeature: ResumeFeatureUseCase, listFeatures: ListFeaturesUseCase, showFeature: ShowFeatureUseCase, listRepositories: ListRepositoriesUseCase);
|
|
40
|
+
/**
|
|
41
|
+
* Execute a messaging command and return a human-readable response.
|
|
42
|
+
*/
|
|
43
|
+
execute(cmd: MessagingCommand): Promise<string>;
|
|
44
|
+
private handleNew;
|
|
45
|
+
private handleApprove;
|
|
46
|
+
private handleReject;
|
|
47
|
+
private handleStop;
|
|
48
|
+
private handleResume;
|
|
49
|
+
private handleStatus;
|
|
50
|
+
/** Resolve a feature by exact ID or prefix match */
|
|
51
|
+
private resolveFeature;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=command-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-executor.d.ts","sourceRoot":"","sources":["../../../../../../../packages/core/src/infrastructure/services/messaging/command-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAW,MAAM,qCAAqC,CAAC;AACrF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gFAAgF,CAAC;AACzH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mEAAmE,CAAC;AAC7G,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kEAAkE,CAAC;AAC3G,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2EAA2E,CAAC;AACtH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qEAAqE,CAAC;AAClH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oEAAoE,CAAC;AAChH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kEAAkE,CAAC;AAC5G,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oEAAoE,CAAC;AAC/G,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2EAA2E,CAAC;AAkBzH;;GAEG;AACH,qBAAa,wBAAwB;IAEjC,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;gBARhB,WAAW,EAAE,kBAAkB,EAC/B,aAAa,EAAE,oBAAoB,EACnC,eAAe,EAAE,sBAAsB,EACvC,cAAc,EAAE,qBAAqB,EACrC,YAAY,EAAE,mBAAmB,EACjC,aAAa,EAAE,oBAAoB,EACnC,YAAY,EAAE,mBAAmB,EACjC,WAAW,EAAE,kBAAkB,EAC/B,gBAAgB,EAAE,uBAAuB;IAG5D;;OAEG;IACG,OAAO,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC;YAqBvC,SAAS;YA0BT,aAAa;YAwBb,YAAY;YA2BZ,UAAU;YAwBV,YAAY;YAaZ,YAAY;IAkB1B,oDAAoD;YACtC,cAAc;CAM7B"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Messaging Command Executor
|
|
3
|
+
*
|
|
4
|
+
* Maps inbound MessagingCommand payloads from the Gateway tunnel
|
|
5
|
+
* to existing Shep use case invocations. This is the bridge between
|
|
6
|
+
* external messaging commands and the application layer.
|
|
7
|
+
*
|
|
8
|
+
* All commands are mapped to existing use cases — no new business logic
|
|
9
|
+
* is introduced here. The executor is a thin translation layer.
|
|
10
|
+
*
|
|
11
|
+
* Feature ID resolution: messaging commands use short IDs (first 8 chars
|
|
12
|
+
* of the UUID). The ShowFeatureUseCase and ResumeFeatureUseCase support
|
|
13
|
+
* prefix matching via findByIdPrefix. For approve/reject/stop, we resolve
|
|
14
|
+
* the feature first, then use its agentRunId.
|
|
15
|
+
*/
|
|
16
|
+
const HELP_TEXT = `Available commands:
|
|
17
|
+
/new <description> — Create a new feature
|
|
18
|
+
/approve <id> — Approve gate on feature
|
|
19
|
+
/reject <id> [feedback] — Reject with feedback
|
|
20
|
+
/stop <id> — Stop agent on feature
|
|
21
|
+
/resume <id> — Resume paused feature
|
|
22
|
+
/status — List all active features
|
|
23
|
+
/status <id> — Show detail for feature
|
|
24
|
+
/help — Show this help text`;
|
|
25
|
+
/** Format a feature for display in messaging */
|
|
26
|
+
function formatFeature(f) {
|
|
27
|
+
const shortId = f.id.slice(0, 8);
|
|
28
|
+
return `#${shortId} "${f.name}" — ${f.lifecycle}`;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Execute messaging commands by delegating to existing use cases.
|
|
32
|
+
*/
|
|
33
|
+
export class MessagingCommandExecutor {
|
|
34
|
+
featureRepo;
|
|
35
|
+
createFeature;
|
|
36
|
+
approveAgentRun;
|
|
37
|
+
rejectAgentRun;
|
|
38
|
+
stopAgentRun;
|
|
39
|
+
resumeFeature;
|
|
40
|
+
listFeatures;
|
|
41
|
+
showFeature;
|
|
42
|
+
listRepositories;
|
|
43
|
+
constructor(featureRepo, createFeature, approveAgentRun, rejectAgentRun, stopAgentRun, resumeFeature, listFeatures, showFeature, listRepositories) {
|
|
44
|
+
this.featureRepo = featureRepo;
|
|
45
|
+
this.createFeature = createFeature;
|
|
46
|
+
this.approveAgentRun = approveAgentRun;
|
|
47
|
+
this.rejectAgentRun = rejectAgentRun;
|
|
48
|
+
this.stopAgentRun = stopAgentRun;
|
|
49
|
+
this.resumeFeature = resumeFeature;
|
|
50
|
+
this.listFeatures = listFeatures;
|
|
51
|
+
this.showFeature = showFeature;
|
|
52
|
+
this.listRepositories = listRepositories;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Execute a messaging command and return a human-readable response.
|
|
56
|
+
*/
|
|
57
|
+
async execute(cmd) {
|
|
58
|
+
switch (cmd.command) {
|
|
59
|
+
case 'new':
|
|
60
|
+
return this.handleNew(cmd);
|
|
61
|
+
case 'approve':
|
|
62
|
+
return this.handleApprove(cmd);
|
|
63
|
+
case 'reject':
|
|
64
|
+
return this.handleReject(cmd);
|
|
65
|
+
case 'stop':
|
|
66
|
+
return this.handleStop(cmd);
|
|
67
|
+
case 'resume':
|
|
68
|
+
return this.handleResume(cmd);
|
|
69
|
+
case 'status':
|
|
70
|
+
return this.handleStatus(cmd);
|
|
71
|
+
case 'help':
|
|
72
|
+
return HELP_TEXT;
|
|
73
|
+
default:
|
|
74
|
+
return `Unknown command: ${cmd.command}. Send /help for available commands.`;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async handleNew(cmd) {
|
|
78
|
+
if (!cmd.args) {
|
|
79
|
+
return 'Usage: /new <feature description>';
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
// Resolve a default repository path from the first tracked repository
|
|
83
|
+
const repos = await this.listRepositories.execute();
|
|
84
|
+
if (repos.length === 0) {
|
|
85
|
+
return 'No repositories configured. Add a repository in the Shep UI first.';
|
|
86
|
+
}
|
|
87
|
+
const result = await this.createFeature.execute({
|
|
88
|
+
userInput: cmd.args,
|
|
89
|
+
repositoryPath: repos[0].path,
|
|
90
|
+
fast: true,
|
|
91
|
+
push: true,
|
|
92
|
+
openPr: true,
|
|
93
|
+
});
|
|
94
|
+
const shortId = result.feature.id.slice(0, 8);
|
|
95
|
+
return `Started: "${cmd.args}" — feature #${shortId}`;
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
return `Failed to create feature: ${error instanceof Error ? error.message : String(error)}`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async handleApprove(cmd) {
|
|
102
|
+
if (!cmd.featureId) {
|
|
103
|
+
return 'Usage: /approve <feature_id>';
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const feature = await this.resolveFeature(cmd.featureId);
|
|
107
|
+
if (!feature) {
|
|
108
|
+
return `Feature #${cmd.featureId} not found`;
|
|
109
|
+
}
|
|
110
|
+
if (!feature.agentRunId) {
|
|
111
|
+
return `Feature #${cmd.featureId} has no active agent run`;
|
|
112
|
+
}
|
|
113
|
+
const result = await this.approveAgentRun.execute(feature.agentRunId);
|
|
114
|
+
if (!result.approved) {
|
|
115
|
+
return `Cannot approve: ${result.reason}`;
|
|
116
|
+
}
|
|
117
|
+
return `Approved feature #${cmd.featureId}`;
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
return `Failed to approve: ${error instanceof Error ? error.message : String(error)}`;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async handleReject(cmd) {
|
|
124
|
+
if (!cmd.featureId) {
|
|
125
|
+
return 'Usage: /reject <feature_id> [feedback]';
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
const feature = await this.resolveFeature(cmd.featureId);
|
|
129
|
+
if (!feature) {
|
|
130
|
+
return `Feature #${cmd.featureId} not found`;
|
|
131
|
+
}
|
|
132
|
+
if (!feature.agentRunId) {
|
|
133
|
+
return `Feature #${cmd.featureId} has no active agent run`;
|
|
134
|
+
}
|
|
135
|
+
const result = await this.rejectAgentRun.execute(feature.agentRunId, cmd.args ?? 'Rejected via messaging');
|
|
136
|
+
if (!result.rejected) {
|
|
137
|
+
return `Cannot reject: ${result.reason}`;
|
|
138
|
+
}
|
|
139
|
+
return `Rejected feature #${cmd.featureId}${cmd.args ? ' with feedback' : ''}`;
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
return `Failed to reject: ${error instanceof Error ? error.message : String(error)}`;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async handleStop(cmd) {
|
|
146
|
+
if (!cmd.featureId) {
|
|
147
|
+
return 'Usage: /stop <feature_id>';
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
const feature = await this.resolveFeature(cmd.featureId);
|
|
151
|
+
if (!feature) {
|
|
152
|
+
return `Feature #${cmd.featureId} not found`;
|
|
153
|
+
}
|
|
154
|
+
if (!feature.agentRunId) {
|
|
155
|
+
return `Feature #${cmd.featureId} has no active agent run`;
|
|
156
|
+
}
|
|
157
|
+
const result = await this.stopAgentRun.execute(feature.agentRunId);
|
|
158
|
+
if (!result.stopped) {
|
|
159
|
+
return `Cannot stop: ${result.reason}`;
|
|
160
|
+
}
|
|
161
|
+
return `Stopped agent on feature #${cmd.featureId}`;
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
return `Failed to stop: ${error instanceof Error ? error.message : String(error)}`;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async handleResume(cmd) {
|
|
168
|
+
if (!cmd.featureId) {
|
|
169
|
+
return 'Usage: /resume <feature_id>';
|
|
170
|
+
}
|
|
171
|
+
try {
|
|
172
|
+
await this.resumeFeature.execute(cmd.featureId);
|
|
173
|
+
return `Resumed feature #${cmd.featureId}`;
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
return `Failed to resume: ${error instanceof Error ? error.message : String(error)}`;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async handleStatus(cmd) {
|
|
180
|
+
try {
|
|
181
|
+
if (cmd.featureId) {
|
|
182
|
+
const feature = await this.showFeature.execute(cmd.featureId);
|
|
183
|
+
return formatFeature(feature);
|
|
184
|
+
}
|
|
185
|
+
const features = await this.listFeatures.execute();
|
|
186
|
+
if (features.length === 0) {
|
|
187
|
+
return 'No active features.';
|
|
188
|
+
}
|
|
189
|
+
return features.map(formatFeature).join('\n');
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
return `Failed to get status: ${error instanceof Error ? error.message : String(error)}`;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/** Resolve a feature by exact ID or prefix match */
|
|
196
|
+
async resolveFeature(featureId) {
|
|
197
|
+
return ((await this.featureRepo.findById(featureId)) ??
|
|
198
|
+
(await this.featureRepo.findByIdPrefix(featureId)));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content Sanitizer
|
|
3
|
+
*
|
|
4
|
+
* Sanitizes outbound messages to ensure no sensitive content
|
|
5
|
+
* (file paths, environment variables, code blocks, secrets)
|
|
6
|
+
* is transmitted through third-party messaging platforms.
|
|
7
|
+
*
|
|
8
|
+
* Security requirement FR-6: no source code, diffs, or file
|
|
9
|
+
* contents transmitted through messaging platforms.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Strip sensitive content from a message before sending to a messaging platform.
|
|
13
|
+
*
|
|
14
|
+
* Removes:
|
|
15
|
+
* - Absolute file paths
|
|
16
|
+
* - Environment variable assignments
|
|
17
|
+
* - Code blocks (fenced with backticks)
|
|
18
|
+
* - Potential secret patterns (API keys, tokens)
|
|
19
|
+
*
|
|
20
|
+
* Truncates to messaging-safe length.
|
|
21
|
+
*/
|
|
22
|
+
export declare function sanitizeForMessaging(text: string): string;
|
|
23
|
+
//# sourceMappingURL=content-sanitizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-sanitizer.d.ts","sourceRoot":"","sources":["../../../../../../../packages/core/src/infrastructure/services/messaging/content-sanitizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAsBzD"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content Sanitizer
|
|
3
|
+
*
|
|
4
|
+
* Sanitizes outbound messages to ensure no sensitive content
|
|
5
|
+
* (file paths, environment variables, code blocks, secrets)
|
|
6
|
+
* is transmitted through third-party messaging platforms.
|
|
7
|
+
*
|
|
8
|
+
* Security requirement FR-6: no source code, diffs, or file
|
|
9
|
+
* contents transmitted through messaging platforms.
|
|
10
|
+
*/
|
|
11
|
+
const MAX_MESSAGE_LENGTH = 4000;
|
|
12
|
+
/**
|
|
13
|
+
* Strip sensitive content from a message before sending to a messaging platform.
|
|
14
|
+
*
|
|
15
|
+
* Removes:
|
|
16
|
+
* - Absolute file paths
|
|
17
|
+
* - Environment variable assignments
|
|
18
|
+
* - Code blocks (fenced with backticks)
|
|
19
|
+
* - Potential secret patterns (API keys, tokens)
|
|
20
|
+
*
|
|
21
|
+
* Truncates to messaging-safe length.
|
|
22
|
+
*/
|
|
23
|
+
export function sanitizeForMessaging(text) {
|
|
24
|
+
let sanitized = text;
|
|
25
|
+
// Strip absolute file paths (Unix and Windows)
|
|
26
|
+
sanitized = sanitized.replace(/(?:\/[\w.\-/]+){2,}/g, '[path]');
|
|
27
|
+
sanitized = sanitized.replace(/[A-Z]:\\[\w.\-\\]+/g, '[path]');
|
|
28
|
+
// Strip env-var-like patterns (KEY=value)
|
|
29
|
+
sanitized = sanitized.replace(/[A-Z_]{3,}=\S+/g, '[env]');
|
|
30
|
+
// Strip fenced code blocks
|
|
31
|
+
sanitized = sanitized.replace(/```[\s\S]*?```/g, '[code block]');
|
|
32
|
+
// Strip inline code that looks like file content
|
|
33
|
+
sanitized = sanitized.replace(/`[^`]{100,}`/g, '[code]');
|
|
34
|
+
// Truncate to messaging-safe length
|
|
35
|
+
if (sanitized.length > MAX_MESSAGE_LENGTH) {
|
|
36
|
+
sanitized = `${sanitized.slice(0, MAX_MESSAGE_LENGTH - 3)}...`;
|
|
37
|
+
}
|
|
38
|
+
return sanitized;
|
|
39
|
+
}
|
package/dist/packages/core/src/infrastructure/services/messaging/messaging-tunnel.adapter.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Messaging Tunnel Adapter
|
|
3
|
+
*
|
|
4
|
+
* Manages the WebSocket tunnel connection to the Commands.com Gateway
|
|
5
|
+
* for bidirectional messaging between Shep and external platforms
|
|
6
|
+
* (Telegram, WhatsApp).
|
|
7
|
+
*
|
|
8
|
+
* Uses Node.js built-in WebSocket API (available since Node 21).
|
|
9
|
+
* Auth token is passed as a URL query parameter since the browser-compatible
|
|
10
|
+
* WebSocket API does not support custom headers.
|
|
11
|
+
*
|
|
12
|
+
* Tunnel frame types:
|
|
13
|
+
* - tunnel.messaging.outbound: Shep → Gateway (notifications, command responses, chat responses)
|
|
14
|
+
* - tunnel.messaging.inbound: Gateway → Shep (commands, chat messages)
|
|
15
|
+
*/
|
|
16
|
+
import type { MessagingNotification, MessagingCommand } from '../../../domain/generated/output.js';
|
|
17
|
+
type CommandHandler = (cmd: MessagingCommand) => Promise<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Manages the WebSocket tunnel to the Commands.com Gateway for messaging.
|
|
20
|
+
* Handles connection lifecycle, heartbeats, reconnection, and frame routing.
|
|
21
|
+
*/
|
|
22
|
+
export declare class MessagingTunnelAdapter {
|
|
23
|
+
private readonly gatewayUrl;
|
|
24
|
+
private readonly authToken;
|
|
25
|
+
private ws;
|
|
26
|
+
private commandHandler;
|
|
27
|
+
private heartbeatTimer;
|
|
28
|
+
private reconnectTimer;
|
|
29
|
+
private connected;
|
|
30
|
+
private stopping;
|
|
31
|
+
constructor(gatewayUrl: string, authToken: string);
|
|
32
|
+
/** Register a handler for inbound commands from the Gateway */
|
|
33
|
+
onCommand(handler: CommandHandler): void;
|
|
34
|
+
/** Connect to the Gateway tunnel WebSocket */
|
|
35
|
+
connect(): Promise<void>;
|
|
36
|
+
/** Disconnect from the Gateway tunnel */
|
|
37
|
+
disconnect(): Promise<void>;
|
|
38
|
+
/** Send a notification or chat response to the Gateway for delivery */
|
|
39
|
+
sendNotification(notification: MessagingNotification): void;
|
|
40
|
+
/** Check if the tunnel is currently connected */
|
|
41
|
+
isConnected(): boolean;
|
|
42
|
+
private handleFrame;
|
|
43
|
+
private sendFrame;
|
|
44
|
+
private startHeartbeat;
|
|
45
|
+
private stopHeartbeat;
|
|
46
|
+
private scheduleReconnect;
|
|
47
|
+
private clearReconnect;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=messaging-tunnel.adapter.d.ts.map
|
package/dist/packages/core/src/infrastructure/services/messaging/messaging-tunnel.adapter.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messaging-tunnel.adapter.d.ts","sourceRoot":"","sources":["../../../../../../../packages/core/src/infrastructure/services/messaging/messaging-tunnel.adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAKnG,KAAK,cAAc,GAAG,CAAC,GAAG,EAAE,gBAAgB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAQjE;;;GAGG;AACH,qBAAa,sBAAsB;IAS/B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAT5B,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,cAAc,CAA+C;IACrE,OAAO,CAAC,cAAc,CAA8C;IACpE,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAS;gBAGN,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM;IAGpC,+DAA+D;IAC/D,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IAIxC,8CAA8C;IACxC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAsC9B,yCAAyC;IACnC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAajC,uEAAuE;IACvE,gBAAgB,CAAC,YAAY,EAAE,qBAAqB,GAAG,IAAI;IAO3D,iDAAiD;IACjD,WAAW,IAAI,OAAO;YAIR,WAAW;IAiBzB,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,cAAc;CAMvB"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Messaging Tunnel Adapter
|
|
3
|
+
*
|
|
4
|
+
* Manages the WebSocket tunnel connection to the Commands.com Gateway
|
|
5
|
+
* for bidirectional messaging between Shep and external platforms
|
|
6
|
+
* (Telegram, WhatsApp).
|
|
7
|
+
*
|
|
8
|
+
* Uses Node.js built-in WebSocket API (available since Node 21).
|
|
9
|
+
* Auth token is passed as a URL query parameter since the browser-compatible
|
|
10
|
+
* WebSocket API does not support custom headers.
|
|
11
|
+
*
|
|
12
|
+
* Tunnel frame types:
|
|
13
|
+
* - tunnel.messaging.outbound: Shep → Gateway (notifications, command responses, chat responses)
|
|
14
|
+
* - tunnel.messaging.inbound: Gateway → Shep (commands, chat messages)
|
|
15
|
+
*/
|
|
16
|
+
const RECONNECT_DELAY_MS = 5_000;
|
|
17
|
+
const HEARTBEAT_INTERVAL_MS = 30_000;
|
|
18
|
+
/**
|
|
19
|
+
* Manages the WebSocket tunnel to the Commands.com Gateway for messaging.
|
|
20
|
+
* Handles connection lifecycle, heartbeats, reconnection, and frame routing.
|
|
21
|
+
*/
|
|
22
|
+
export class MessagingTunnelAdapter {
|
|
23
|
+
gatewayUrl;
|
|
24
|
+
authToken;
|
|
25
|
+
ws = null;
|
|
26
|
+
commandHandler = null;
|
|
27
|
+
heartbeatTimer = null;
|
|
28
|
+
reconnectTimer = null;
|
|
29
|
+
connected = false;
|
|
30
|
+
stopping = false;
|
|
31
|
+
constructor(gatewayUrl, authToken) {
|
|
32
|
+
this.gatewayUrl = gatewayUrl;
|
|
33
|
+
this.authToken = authToken;
|
|
34
|
+
}
|
|
35
|
+
/** Register a handler for inbound commands from the Gateway */
|
|
36
|
+
onCommand(handler) {
|
|
37
|
+
this.commandHandler = handler;
|
|
38
|
+
}
|
|
39
|
+
/** Connect to the Gateway tunnel WebSocket */
|
|
40
|
+
async connect() {
|
|
41
|
+
if (this.connected || this.stopping)
|
|
42
|
+
return;
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
const baseUrl = this.gatewayUrl.replace(/^http/, 'ws');
|
|
45
|
+
const tunnelUrl = `${baseUrl}/gateway/v1/integrations/tunnel/connect?token=${encodeURIComponent(this.authToken)}`;
|
|
46
|
+
this.ws = new WebSocket(tunnelUrl);
|
|
47
|
+
this.ws.addEventListener('open', () => {
|
|
48
|
+
this.connected = true;
|
|
49
|
+
this.startHeartbeat();
|
|
50
|
+
resolve();
|
|
51
|
+
});
|
|
52
|
+
this.ws.addEventListener('message', (event) => {
|
|
53
|
+
const data = typeof event.data === 'string' ? event.data : String(event.data);
|
|
54
|
+
this.handleFrame(data).catch(() => {
|
|
55
|
+
// Frame handling errors are non-fatal — silently drop malformed frames
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
this.ws.addEventListener('close', () => {
|
|
59
|
+
this.connected = false;
|
|
60
|
+
this.stopHeartbeat();
|
|
61
|
+
if (!this.stopping) {
|
|
62
|
+
this.scheduleReconnect();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
this.ws.addEventListener('error', () => {
|
|
66
|
+
if (!this.connected) {
|
|
67
|
+
reject(new Error('WebSocket connection to Gateway failed'));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/** Disconnect from the Gateway tunnel */
|
|
73
|
+
async disconnect() {
|
|
74
|
+
this.stopping = true;
|
|
75
|
+
this.stopHeartbeat();
|
|
76
|
+
this.clearReconnect();
|
|
77
|
+
if (this.ws) {
|
|
78
|
+
this.ws.close();
|
|
79
|
+
this.ws = null;
|
|
80
|
+
}
|
|
81
|
+
this.connected = false;
|
|
82
|
+
}
|
|
83
|
+
/** Send a notification or chat response to the Gateway for delivery */
|
|
84
|
+
sendNotification(notification) {
|
|
85
|
+
this.sendFrame({
|
|
86
|
+
type: 'tunnel.messaging.outbound',
|
|
87
|
+
payload: JSON.stringify(notification),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/** Check if the tunnel is currently connected */
|
|
91
|
+
isConnected() {
|
|
92
|
+
return this.connected;
|
|
93
|
+
}
|
|
94
|
+
async handleFrame(data) {
|
|
95
|
+
const frame = JSON.parse(data);
|
|
96
|
+
if (frame.type === 'tunnel.messaging.inbound' && this.commandHandler) {
|
|
97
|
+
const cmd = JSON.parse(frame.payload);
|
|
98
|
+
const response = await this.commandHandler(cmd);
|
|
99
|
+
// Send response back through tunnel
|
|
100
|
+
this.sendNotification({
|
|
101
|
+
event: 'command.response',
|
|
102
|
+
featureId: cmd.featureId ?? '',
|
|
103
|
+
title: '',
|
|
104
|
+
message: response,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
sendFrame(frame) {
|
|
109
|
+
if (!this.ws || !this.connected)
|
|
110
|
+
return;
|
|
111
|
+
this.ws.send(JSON.stringify(frame));
|
|
112
|
+
}
|
|
113
|
+
startHeartbeat() {
|
|
114
|
+
this.heartbeatTimer = setInterval(() => {
|
|
115
|
+
this.sendFrame({ type: 'tunnel.heartbeat', payload: '' });
|
|
116
|
+
}, HEARTBEAT_INTERVAL_MS);
|
|
117
|
+
this.heartbeatTimer.unref();
|
|
118
|
+
}
|
|
119
|
+
stopHeartbeat() {
|
|
120
|
+
if (this.heartbeatTimer) {
|
|
121
|
+
clearInterval(this.heartbeatTimer);
|
|
122
|
+
this.heartbeatTimer = null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
scheduleReconnect() {
|
|
126
|
+
this.clearReconnect();
|
|
127
|
+
this.reconnectTimer = setTimeout(() => {
|
|
128
|
+
this.connect().catch(() => {
|
|
129
|
+
// Reconnect failed, will retry via close event
|
|
130
|
+
});
|
|
131
|
+
}, RECONNECT_DELAY_MS);
|
|
132
|
+
this.reconnectTimer.unref();
|
|
133
|
+
}
|
|
134
|
+
clearReconnect() {
|
|
135
|
+
if (this.reconnectTimer) {
|
|
136
|
+
clearTimeout(this.reconnectTimer);
|
|
137
|
+
this.reconnectTimer = null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Messaging Service
|
|
3
|
+
*
|
|
4
|
+
* Core orchestrator for the external messaging remote control feature.
|
|
5
|
+
* Implements IMessagingService and coordinates:
|
|
6
|
+
* - Tunnel connection to the Commands.com Gateway
|
|
7
|
+
* - Command execution (inbound commands → use cases)
|
|
8
|
+
* - Notification emission (lifecycle events → tunnel → phone)
|
|
9
|
+
* - Chat relay (bidirectional agent ↔ messaging)
|
|
10
|
+
*
|
|
11
|
+
* Lifecycle:
|
|
12
|
+
* 1. isConfigured() checks if Gateway URL and platform credentials exist
|
|
13
|
+
* 2. start() connects to the Gateway tunnel and wires up handlers
|
|
14
|
+
* 3. stop() disconnects and cleans up all resources
|
|
15
|
+
*/
|
|
16
|
+
import type { IMessagingService } from '../../../application/ports/output/services/messaging-service.interface.js';
|
|
17
|
+
import type { MessagingNotification, MessagingConfig } from '../../../domain/generated/output.js';
|
|
18
|
+
import type { NotificationBus } from '../notifications/notification-bus.js';
|
|
19
|
+
import type { IFeatureRepository } from '../../../application/ports/output/repositories/feature-repository.interface.js';
|
|
20
|
+
import type { ListFeaturesUseCase } from '../../../application/use-cases/features/list-features.use-case.js';
|
|
21
|
+
import type { ShowFeatureUseCase } from '../../../application/use-cases/features/show-feature.use-case.js';
|
|
22
|
+
import type { CreateFeatureUseCase } from '../../../application/use-cases/features/create/create-feature.use-case.js';
|
|
23
|
+
import type { ApproveAgentRunUseCase } from '../../../application/use-cases/agents/approve-agent-run.use-case.js';
|
|
24
|
+
import type { RejectAgentRunUseCase } from '../../../application/use-cases/agents/reject-agent-run.use-case.js';
|
|
25
|
+
import type { StopAgentRunUseCase } from '../../../application/use-cases/agents/stop-agent-run.use-case.js';
|
|
26
|
+
import type { ResumeFeatureUseCase } from '../../../application/use-cases/features/resume-feature.use-case.js';
|
|
27
|
+
import type { ListRepositoriesUseCase } from '../../../application/use-cases/repositories/list-repositories.use-case.js';
|
|
28
|
+
interface MessagingServiceDeps {
|
|
29
|
+
config: MessagingConfig;
|
|
30
|
+
authToken: string;
|
|
31
|
+
notificationBus: NotificationBus;
|
|
32
|
+
featureRepo: IFeatureRepository;
|
|
33
|
+
createFeature: CreateFeatureUseCase;
|
|
34
|
+
approveAgentRun: ApproveAgentRunUseCase;
|
|
35
|
+
rejectAgentRun: RejectAgentRunUseCase;
|
|
36
|
+
stopAgentRun: StopAgentRunUseCase;
|
|
37
|
+
resumeFeature: ResumeFeatureUseCase;
|
|
38
|
+
listFeatures: ListFeaturesUseCase;
|
|
39
|
+
showFeature: ShowFeatureUseCase;
|
|
40
|
+
listRepositories: ListRepositoriesUseCase;
|
|
41
|
+
}
|
|
42
|
+
export declare class MessagingService implements IMessagingService {
|
|
43
|
+
private readonly deps;
|
|
44
|
+
private tunnelAdapter;
|
|
45
|
+
private commandExecutor;
|
|
46
|
+
private notificationEmitter;
|
|
47
|
+
private chatRelay;
|
|
48
|
+
private started;
|
|
49
|
+
constructor(deps: MessagingServiceDeps);
|
|
50
|
+
isConfigured(): boolean;
|
|
51
|
+
isConnected(): boolean;
|
|
52
|
+
start(): Promise<void>;
|
|
53
|
+
stop(): Promise<void>;
|
|
54
|
+
sendNotification(notification: MessagingNotification): Promise<void>;
|
|
55
|
+
private handleChatControl;
|
|
56
|
+
}
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=messaging.service.d.ts.map
|