@essentialai/cogent-server 2.0.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/.env.example +68 -0
- package/CHANGELOG.md +16 -0
- package/Caddyfile +8 -0
- package/Dockerfile +46 -0
- package/LICENSE +190 -0
- package/README.md +89 -0
- package/config.json.example +16 -0
- package/dist/__tests__/helpers.d.ts +56 -0
- package/dist/__tests__/helpers.d.ts.map +1 -0
- package/dist/__tests__/helpers.js +138 -0
- package/dist/__tests__/helpers.js.map +1 -0
- package/dist/app.d.ts +38 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +60 -0
- package/dist/app.js.map +1 -0
- package/dist/config.d.ts +88 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +148 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +102 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/auth.d.ts +15 -0
- package/dist/middleware/auth.d.ts.map +1 -0
- package/dist/middleware/auth.js +47 -0
- package/dist/middleware/auth.js.map +1 -0
- package/dist/middleware/error-handler.d.ts +14 -0
- package/dist/middleware/error-handler.d.ts.map +1 -0
- package/dist/middleware/error-handler.js +26 -0
- package/dist/middleware/error-handler.js.map +1 -0
- package/dist/middleware/not-found.d.ts +8 -0
- package/dist/middleware/not-found.d.ts.map +1 -0
- package/dist/middleware/not-found.js +12 -0
- package/dist/middleware/not-found.js.map +1 -0
- package/dist/middleware/request-logger.d.ts +17 -0
- package/dist/middleware/request-logger.d.ts.map +1 -0
- package/dist/middleware/request-logger.js +65 -0
- package/dist/middleware/request-logger.js.map +1 -0
- package/dist/middleware/ws-auth.d.ts +21 -0
- package/dist/middleware/ws-auth.d.ts.map +1 -0
- package/dist/middleware/ws-auth.js +59 -0
- package/dist/middleware/ws-auth.js.map +1 -0
- package/dist/routes/health.d.ts +11 -0
- package/dist/routes/health.d.ts.map +1 -0
- package/dist/routes/health.js +34 -0
- package/dist/routes/health.js.map +1 -0
- package/dist/routes/messages.d.ts +19 -0
- package/dist/routes/messages.d.ts.map +1 -0
- package/dist/routes/messages.js +154 -0
- package/dist/routes/messages.js.map +1 -0
- package/dist/routes/peers.d.ts +17 -0
- package/dist/routes/peers.d.ts.map +1 -0
- package/dist/routes/peers.js +169 -0
- package/dist/routes/peers.js.map +1 -0
- package/dist/routes/poll.d.ts +15 -0
- package/dist/routes/poll.d.ts.map +1 -0
- package/dist/routes/poll.js +97 -0
- package/dist/routes/poll.js.map +1 -0
- package/dist/routes/sessions.d.ts +14 -0
- package/dist/routes/sessions.d.ts.map +1 -0
- package/dist/routes/sessions.js +113 -0
- package/dist/routes/sessions.js.map +1 -0
- package/dist/routes/ui.d.ts +21 -0
- package/dist/routes/ui.d.ts.map +1 -0
- package/dist/routes/ui.js +173 -0
- package/dist/routes/ui.js.map +1 -0
- package/dist/routes/validation-hook.d.ts +18 -0
- package/dist/routes/validation-hook.d.ts.map +1 -0
- package/dist/routes/validation-hook.js +24 -0
- package/dist/routes/validation-hook.js.map +1 -0
- package/dist/services/auth-service.d.ts +48 -0
- package/dist/services/auth-service.d.ts.map +1 -0
- package/dist/services/auth-service.js +63 -0
- package/dist/services/auth-service.js.map +1 -0
- package/dist/services/connection-manager.d.ts +108 -0
- package/dist/services/connection-manager.d.ts.map +1 -0
- package/dist/services/connection-manager.js +216 -0
- package/dist/services/connection-manager.js.map +1 -0
- package/dist/services/message-queue.d.ts +56 -0
- package/dist/services/message-queue.d.ts.map +1 -0
- package/dist/services/message-queue.js +164 -0
- package/dist/services/message-queue.js.map +1 -0
- package/dist/services/peer-cleanup.d.ts +39 -0
- package/dist/services/peer-cleanup.d.ts.map +1 -0
- package/dist/services/peer-cleanup.js +96 -0
- package/dist/services/peer-cleanup.js.map +1 -0
- package/dist/services/session-cleanup.d.ts +44 -0
- package/dist/services/session-cleanup.d.ts.map +1 -0
- package/dist/services/session-cleanup.js +100 -0
- package/dist/services/session-cleanup.js.map +1 -0
- package/dist/services/session-store.d.ts +103 -0
- package/dist/services/session-store.d.ts.map +1 -0
- package/dist/services/session-store.js +292 -0
- package/dist/services/session-store.js.map +1 -0
- package/dist/services/stats-service.d.ts +48 -0
- package/dist/services/stats-service.d.ts.map +1 -0
- package/dist/services/stats-service.js +77 -0
- package/dist/services/stats-service.js.map +1 -0
- package/dist/types.d.ts +60 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/components/Footer.d.ts +7 -0
- package/dist/ui/components/Footer.d.ts.map +1 -0
- package/dist/ui/components/Footer.js +17 -0
- package/dist/ui/components/Footer.js.map +1 -0
- package/dist/ui/components/Layout.d.ts +13 -0
- package/dist/ui/components/Layout.d.ts.map +1 -0
- package/dist/ui/components/Layout.js +11 -0
- package/dist/ui/components/Layout.js.map +1 -0
- package/dist/ui/components/NavBar.d.ts +12 -0
- package/dist/ui/components/NavBar.d.ts.map +1 -0
- package/dist/ui/components/NavBar.js +60 -0
- package/dist/ui/components/NavBar.js.map +1 -0
- package/dist/ui/components/StatCard.d.ts +14 -0
- package/dist/ui/components/StatCard.d.ts.map +1 -0
- package/dist/ui/components/StatCard.js +32 -0
- package/dist/ui/components/StatCard.js.map +1 -0
- package/dist/ui/components/Terminal.d.ts +13 -0
- package/dist/ui/components/Terminal.d.ts.map +1 -0
- package/dist/ui/components/Terminal.js +37 -0
- package/dist/ui/components/Terminal.js.map +1 -0
- package/dist/ui/pages/AdminDashboard.d.ts +13 -0
- package/dist/ui/pages/AdminDashboard.d.ts.map +1 -0
- package/dist/ui/pages/AdminDashboard.js +59 -0
- package/dist/ui/pages/AdminDashboard.js.map +1 -0
- package/dist/ui/pages/HowToPage.d.ts +8 -0
- package/dist/ui/pages/HowToPage.d.ts.map +1 -0
- package/dist/ui/pages/HowToPage.js +312 -0
- package/dist/ui/pages/HowToPage.js.map +1 -0
- package/dist/ui/pages/LandingPage.d.ts +13 -0
- package/dist/ui/pages/LandingPage.d.ts.map +1 -0
- package/dist/ui/pages/LandingPage.js +160 -0
- package/dist/ui/pages/LandingPage.js.map +1 -0
- package/dist/ui/pages/MessageLog.d.ts +25 -0
- package/dist/ui/pages/MessageLog.d.ts.map +1 -0
- package/dist/ui/pages/MessageLog.js +146 -0
- package/dist/ui/pages/MessageLog.js.map +1 -0
- package/dist/ui/pages/SessionDetail.d.ts +14 -0
- package/dist/ui/pages/SessionDetail.d.ts.map +1 -0
- package/dist/ui/pages/SessionDetail.js +165 -0
- package/dist/ui/pages/SessionDetail.js.map +1 -0
- package/dist/ui/pages/SessionList.d.ts +22 -0
- package/dist/ui/pages/SessionList.d.ts.map +1 -0
- package/dist/ui/pages/SessionList.js +88 -0
- package/dist/ui/pages/SessionList.js.map +1 -0
- package/dist/ui/styles/theme.d.ts +35 -0
- package/dist/ui/styles/theme.d.ts.map +1 -0
- package/dist/ui/styles/theme.js +65 -0
- package/dist/ui/styles/theme.js.map +1 -0
- package/dist/ws/frames.d.ts +82 -0
- package/dist/ws/frames.d.ts.map +1 -0
- package/dist/ws/frames.js +68 -0
- package/dist/ws/frames.js.map +1 -0
- package/dist/ws/handler.d.ts +26 -0
- package/dist/ws/handler.d.ts.map +1 -0
- package/dist/ws/handler.js +72 -0
- package/dist/ws/handler.js.map +1 -0
- package/dist/ws/heartbeat.d.ts +18 -0
- package/dist/ws/heartbeat.d.ts.map +1 -0
- package/dist/ws/heartbeat.js +39 -0
- package/dist/ws/heartbeat.js.map +1 -0
- package/docker-compose.yml +38 -0
- package/nginx.conf.example +63 -0
- package/package.json +61 -0
package/.env.example
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Cogent Server - Environment Variables
|
|
2
|
+
# Copy this file to .env and customize values as needed.
|
|
3
|
+
|
|
4
|
+
# ============================================================
|
|
5
|
+
# Server Configuration (COGENT_SERVER_* prefix)
|
|
6
|
+
# ============================================================
|
|
7
|
+
|
|
8
|
+
# HTTP port the server listens on
|
|
9
|
+
COGENT_SERVER_PORT=3000
|
|
10
|
+
|
|
11
|
+
# Bind address (0.0.0.0 for all interfaces)
|
|
12
|
+
COGENT_SERVER_HOST=0.0.0.0
|
|
13
|
+
|
|
14
|
+
# Directory for session state files (use /data/sessions in Docker)
|
|
15
|
+
COGENT_SERVER_STATE_DIR=/data/sessions
|
|
16
|
+
|
|
17
|
+
# Log verbosity: debug, info, warn, error
|
|
18
|
+
COGENT_SERVER_LOG_LEVEL=info
|
|
19
|
+
|
|
20
|
+
# bcrypt cost factor for secret hashing (4-31, higher = slower but more secure)
|
|
21
|
+
COGENT_SERVER_BCRYPT_ROUNDS=12
|
|
22
|
+
|
|
23
|
+
# Time in ms before an idle peer is considered stale (default: 30 min)
|
|
24
|
+
COGENT_SERVER_STALE_PEER_TIMEOUT_MS=1800000
|
|
25
|
+
|
|
26
|
+
# Maximum messages stored per session (oldest are dropped)
|
|
27
|
+
COGENT_SERVER_MAX_MESSAGES_PER_SESSION=500
|
|
28
|
+
|
|
29
|
+
# CORS allowed origins (* = all; set to your domain in production)
|
|
30
|
+
COGENT_SERVER_CORS_ORIGIN=*
|
|
31
|
+
|
|
32
|
+
# Admin dashboard password (leave empty to disable admin UI entirely)
|
|
33
|
+
COGENT_SERVER_ADMIN_PASSWORD=changeme
|
|
34
|
+
|
|
35
|
+
# ============================================================
|
|
36
|
+
# WebSocket Settings
|
|
37
|
+
# ============================================================
|
|
38
|
+
|
|
39
|
+
# Interval between heartbeat pings (default: 30s)
|
|
40
|
+
COGENT_SERVER_WS_HEARTBEAT_INTERVAL_MS=30000
|
|
41
|
+
|
|
42
|
+
# Missed pongs before terminating connection (default: 3, giving 90s window)
|
|
43
|
+
COGENT_SERVER_WS_HEARTBEAT_MAX_MISSED=3
|
|
44
|
+
|
|
45
|
+
# Grace period after last WS disconnect before marking peer offline (default: 30s)
|
|
46
|
+
COGENT_SERVER_WS_GRACE_PERIOD_MS=30000
|
|
47
|
+
|
|
48
|
+
# ============================================================
|
|
49
|
+
# Message Queue Settings
|
|
50
|
+
# ============================================================
|
|
51
|
+
|
|
52
|
+
# Queue message TTL in ms (default: 7 days)
|
|
53
|
+
COGENT_SERVER_QUEUE_TTL_MS=604800000
|
|
54
|
+
|
|
55
|
+
# Queue cleanup interval in ms (default: 6 hours)
|
|
56
|
+
COGENT_SERVER_QUEUE_CLEANUP_INTERVAL_MS=21600000
|
|
57
|
+
|
|
58
|
+
# ============================================================
|
|
59
|
+
# Production Settings
|
|
60
|
+
# ============================================================
|
|
61
|
+
|
|
62
|
+
# Set to "production" for JSON structured logging and optimized behavior
|
|
63
|
+
NODE_ENV=production
|
|
64
|
+
|
|
65
|
+
# Domain for Caddy HTTPS (used in Caddyfile via {$DOMAIN:localhost})
|
|
66
|
+
# Set to your actual domain for automatic Let's Encrypt certificates
|
|
67
|
+
# Leave as "localhost" for self-signed certificates (development)
|
|
68
|
+
DOMAIN=localhost
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [2.0.0] - 2026-02-25
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Hono-based REST API with session management, peer registration, and messaging
|
|
7
|
+
- WebSocket real-time message push with heartbeat and offline queuing
|
|
8
|
+
- Bearer token authentication with bcrypt-hashed secrets
|
|
9
|
+
- File-based session persistence (JSON per session)
|
|
10
|
+
- Public landing page with live stats and admin dashboard
|
|
11
|
+
- Graceful shutdown with WebSocket cleanup
|
|
12
|
+
- Label-based session joining with auto-generated human-readable labels
|
|
13
|
+
- Automatic session cleanup after 7 days of inactivity
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- License changed from ISC to Apache 2.0
|
package/Caddyfile
ADDED
package/Dockerfile
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Cogent Server - Multi-stage Docker build
|
|
2
|
+
# Build context must be the project root (parent of server/) so cogent/ is accessible.
|
|
3
|
+
# Usage: docker build -f server/Dockerfile .
|
|
4
|
+
# Or via docker-compose: build context is set to .. automatically.
|
|
5
|
+
|
|
6
|
+
# --- Build stage ---
|
|
7
|
+
FROM node:24-alpine AS builder
|
|
8
|
+
WORKDIR /app
|
|
9
|
+
|
|
10
|
+
# Install dependencies first (layer caching)
|
|
11
|
+
COPY server/package.json server/package-lock.json ./
|
|
12
|
+
COPY cogent/ ./cogent/
|
|
13
|
+
RUN npm ci
|
|
14
|
+
|
|
15
|
+
# Copy source and compile
|
|
16
|
+
COPY server/src/ ./src/
|
|
17
|
+
COPY server/tsconfig.json ./
|
|
18
|
+
RUN npm run build
|
|
19
|
+
|
|
20
|
+
# --- Runtime stage ---
|
|
21
|
+
FROM node:24-alpine
|
|
22
|
+
WORKDIR /app
|
|
23
|
+
|
|
24
|
+
# Create data directory owned by non-root node user
|
|
25
|
+
RUN mkdir -p /data && chown node:node /data
|
|
26
|
+
|
|
27
|
+
# Install production dependencies only
|
|
28
|
+
COPY server/package.json server/package-lock.json ./
|
|
29
|
+
COPY cogent/ ./cogent/
|
|
30
|
+
RUN npm ci --omit=dev && npm cache clean --force
|
|
31
|
+
|
|
32
|
+
# Copy compiled output from builder
|
|
33
|
+
COPY --from=builder /app/dist ./dist
|
|
34
|
+
|
|
35
|
+
# Run as non-root user
|
|
36
|
+
USER node
|
|
37
|
+
|
|
38
|
+
# Health check against the existing /api/health endpoint
|
|
39
|
+
# Alpine has wget (via busybox) but not curl
|
|
40
|
+
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
|
|
41
|
+
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1
|
|
42
|
+
|
|
43
|
+
EXPOSE 3000
|
|
44
|
+
|
|
45
|
+
# Use node directly, NOT npm start -- npm swallows SIGTERM signals
|
|
46
|
+
CMD ["node", "dist/index.js"]
|
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2025-2026 Essential AI Solutions Ltd.
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# @essentialai/cogent-server
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@essentialai/cogent-server)
|
|
4
|
+
[](https://www.npmjs.com/package/@essentialai/cogent-server)
|
|
5
|
+
[](https://www.npmjs.com/package/@essentialai/cogent-server)
|
|
6
|
+
|
|
7
|
+
Cloud relay server for [Cogent bridge](https://cogent.tools) inter-session communication. Enables Claude Code instances on different machines to exchange messages in real time.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **REST API** -- Session management, peer registration, and messaging via Hono
|
|
12
|
+
- **WebSocket push** -- Real-time message delivery with heartbeat and offline queuing
|
|
13
|
+
- **Bearer token auth** -- bcrypt-hashed secrets, SHA-256 token storage
|
|
14
|
+
- **File-based persistence** -- JSON per session, no external database required
|
|
15
|
+
- **Admin dashboard** -- Landing page with live stats at the server root
|
|
16
|
+
- **Graceful shutdown** -- WebSocket cleanup and session persistence on SIGTERM
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
### Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @essentialai/cogent-server
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Configure
|
|
27
|
+
|
|
28
|
+
Set environment variables (all optional with sensible defaults):
|
|
29
|
+
|
|
30
|
+
| Variable | Default | Description |
|
|
31
|
+
|----------|---------|-------------|
|
|
32
|
+
| `COGENT_SERVER_PORT` | `3000` | HTTP server port |
|
|
33
|
+
| `COGENT_SERVER_DATA_DIR` | `./data` | Session data directory |
|
|
34
|
+
| `COGENT_SERVER_MAX_SESSIONS` | `1000` | Maximum concurrent sessions |
|
|
35
|
+
| `COGENT_SERVER_MAX_MESSAGES` | `500` | Messages per session |
|
|
36
|
+
| `COGENT_SERVER_MAX_PEERS` | `10` | Peers per session |
|
|
37
|
+
| `COGENT_SERVER_SESSION_TTL_DAYS` | `7` | Auto-cleanup inactive sessions |
|
|
38
|
+
| `COGENT_SERVER_WS_HEARTBEAT_MS` | `30000` | WebSocket ping interval |
|
|
39
|
+
| `COGENT_SERVER_LOG_LEVEL` | `info` | Log verbosity |
|
|
40
|
+
|
|
41
|
+
### Run
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
# Start the server
|
|
45
|
+
npx @essentialai/cogent-server
|
|
46
|
+
|
|
47
|
+
# Or with custom config
|
|
48
|
+
COGENT_SERVER_PORT=8080 npx @essentialai/cogent-server
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Deploy with Docker
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
docker build -t cogent-server .
|
|
55
|
+
docker run -p 3000:3000 -v ./data:/app/data cogent-server
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
A `docker-compose.yml` and nginx configuration example are included in the package.
|
|
59
|
+
|
|
60
|
+
## API Endpoints
|
|
61
|
+
|
|
62
|
+
| Method | Path | Auth | Description |
|
|
63
|
+
|--------|------|------|-------------|
|
|
64
|
+
| POST | `/api/sessions` | No | Create a new session |
|
|
65
|
+
| POST | `/api/sessions/:id/join` | No | Join an existing session |
|
|
66
|
+
| GET | `/api/sessions/resolve/:label` | No | Resolve label to session ID |
|
|
67
|
+
| POST | `/api/sessions/:id/peers` | Yes | Register a peer |
|
|
68
|
+
| DELETE | `/api/sessions/:id/peers/:peerId` | Yes | Deregister a peer |
|
|
69
|
+
| GET | `/api/sessions/:id/peers` | Yes | List peers |
|
|
70
|
+
| POST | `/api/sessions/:id/messages` | Yes | Send a message |
|
|
71
|
+
| GET | `/api/sessions/:id/messages` | Yes | Get message history |
|
|
72
|
+
| GET | `/api/sessions/:id/poll` | Yes | Poll for new messages |
|
|
73
|
+
| GET | `/api/health` | No | Health check |
|
|
74
|
+
| GET | `/ws` | Yes | WebSocket connection |
|
|
75
|
+
|
|
76
|
+
## Production Deployment
|
|
77
|
+
|
|
78
|
+
The public instance runs at [cogent.tools](https://cogent.tools). For self-hosting, see the included `Dockerfile`, `docker-compose.yml`, `Caddyfile`, and `nginx.conf.example`.
|
|
79
|
+
|
|
80
|
+
## Links
|
|
81
|
+
|
|
82
|
+
- [cogent.tools](https://cogent.tools) -- Public relay server
|
|
83
|
+
- [@essentialai/cogent-bridge](https://www.npmjs.com/package/@essentialai/cogent-bridge) -- MCP client
|
|
84
|
+
- [@essentialai/cogent](https://www.npmjs.com/package/@essentialai/cogent) -- Shared types
|
|
85
|
+
- [GitHub](https://github.com/eaisdevelopment/cogent)
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
Apache-2.0
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"port": 3000,
|
|
3
|
+
"host": "0.0.0.0",
|
|
4
|
+
"stateDir": "/data/sessions",
|
|
5
|
+
"logLevel": "info",
|
|
6
|
+
"bcryptRounds": 12,
|
|
7
|
+
"stalePeerTimeoutMs": 1800000,
|
|
8
|
+
"maxMessagesPerSession": 500,
|
|
9
|
+
"corsOrigin": "*",
|
|
10
|
+
"wsHeartbeatIntervalMs": 30000,
|
|
11
|
+
"wsHeartbeatMaxMissed": 3,
|
|
12
|
+
"wsGracePeriodMs": 30000,
|
|
13
|
+
"queueTtlMs": 604800000,
|
|
14
|
+
"queueCleanupIntervalMs": 21600000,
|
|
15
|
+
"adminPassword": "changeme"
|
|
16
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Hono } from "hono";
|
|
2
|
+
import type { ServerType } from "@hono/node-server";
|
|
3
|
+
import { SessionStore } from "../services/session-store.js";
|
|
4
|
+
import { AuthService } from "../services/auth-service.js";
|
|
5
|
+
import { ConnectionManager } from "../services/connection-manager.js";
|
|
6
|
+
import { MessageQueueService } from "../services/message-queue.js";
|
|
7
|
+
import type { ServerEnv } from "../types.js";
|
|
8
|
+
export interface TestApp {
|
|
9
|
+
app: Hono<ServerEnv>;
|
|
10
|
+
sessionStore: SessionStore;
|
|
11
|
+
authService: AuthService;
|
|
12
|
+
connectionManager: ConnectionManager;
|
|
13
|
+
messageQueue: MessageQueueService;
|
|
14
|
+
cleanup: () => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create a fully-wired test app with real SessionStore and AuthService.
|
|
18
|
+
* Each call creates a fresh temp directory for isolation.
|
|
19
|
+
*
|
|
20
|
+
* @param maxMessages - Message cap for the session store (default 500, use small value for cap tests)
|
|
21
|
+
*/
|
|
22
|
+
export declare function createTestApp(maxMessages?: number): Promise<TestApp>;
|
|
23
|
+
/**
|
|
24
|
+
* Helper to create a session and get a bearer token.
|
|
25
|
+
* Returns { sessionId, token } for use in subsequent requests.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createSessionAndGetToken(app: Hono<ServerEnv>, secret?: string): Promise<{
|
|
28
|
+
sessionId: string;
|
|
29
|
+
token: string;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Helper to register a peer in a session.
|
|
33
|
+
* Returns the PeerInfo response body.
|
|
34
|
+
*/
|
|
35
|
+
export declare function registerPeer(app: Hono<ServerEnv>, sessionId: string, token: string, peerId: string, label?: string): Promise<Record<string, unknown>>;
|
|
36
|
+
/**
|
|
37
|
+
* Extended TestApp that includes a real HTTP server for WebSocket testing.
|
|
38
|
+
* WebSocket upgrade requires a real HTTP server (not app.request()).
|
|
39
|
+
*/
|
|
40
|
+
export interface TestWsApp extends TestApp {
|
|
41
|
+
server: ServerType;
|
|
42
|
+
port: number;
|
|
43
|
+
/** Build a ws:// URL for the given session, token, and peerId. */
|
|
44
|
+
wsUrl: (sessionId: string, token: string, peerId: string) => string;
|
|
45
|
+
/** Shut down the HTTP server and close all WS connections. */
|
|
46
|
+
shutdown: () => Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create a test app backed by a real HTTP server on an ephemeral port.
|
|
50
|
+
* Required for WebSocket integration tests -- WS upgrade cannot work
|
|
51
|
+
* with Hono's app.request() testing mode.
|
|
52
|
+
*
|
|
53
|
+
* @param maxMessages - Message cap for the session store (default 500)
|
|
54
|
+
*/
|
|
55
|
+
export declare function createTestWsApp(maxMessages?: number): Promise<TestWsApp>;
|
|
56
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/__tests__/helpers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAGjC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAGnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACrB,YAAY,EAAE,YAAY,CAAC;IAC3B,WAAW,EAAE,WAAW,CAAC;IACzB,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,YAAY,EAAE,mBAAmB,CAAC;IAClC,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,WAAW,SAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAoCvE;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,EACpB,MAAM,SAAsB,GAC3B,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAQ/C;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAChC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,EACpB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,KAAK,SAAmB,GACvB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAclC;AAED;;;GAGG;AACH,MAAM,WAAW,SAAU,SAAQ,OAAO;IACxC,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,kEAAkE;IAClE,KAAK,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;IACpE,8DAA8D;IAC9D,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,WAAW,SAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAyD3E"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { createAdaptorServer } from "@hono/node-server";
|
|
5
|
+
import { SessionStore } from "../services/session-store.js";
|
|
6
|
+
import { AuthService } from "../services/auth-service.js";
|
|
7
|
+
import { ConnectionManager } from "../services/connection-manager.js";
|
|
8
|
+
import { MessageQueueService } from "../services/message-queue.js";
|
|
9
|
+
import { StatsService } from "../services/stats-service.js";
|
|
10
|
+
import { createApp } from "../app.js";
|
|
11
|
+
/**
|
|
12
|
+
* Create a fully-wired test app with real SessionStore and AuthService.
|
|
13
|
+
* Each call creates a fresh temp directory for isolation.
|
|
14
|
+
*
|
|
15
|
+
* @param maxMessages - Message cap for the session store (default 500, use small value for cap tests)
|
|
16
|
+
*/
|
|
17
|
+
export async function createTestApp(maxMessages = 500) {
|
|
18
|
+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "route-test-"));
|
|
19
|
+
const sessionStore = new SessionStore(tmpDir, maxMessages);
|
|
20
|
+
const authService = new AuthService(4); // Low rounds for fast tests
|
|
21
|
+
const connectionManager = new ConnectionManager(30_000);
|
|
22
|
+
const messageQueue = new MessageQueueService(sessionStore);
|
|
23
|
+
await sessionStore.init();
|
|
24
|
+
const startTime = Date.now();
|
|
25
|
+
const statsService = new StatsService(sessionStore, connectionManager, startTime);
|
|
26
|
+
const { app } = createApp({
|
|
27
|
+
sessionStore,
|
|
28
|
+
authService,
|
|
29
|
+
startTime,
|
|
30
|
+
maxMessages,
|
|
31
|
+
connectionManager,
|
|
32
|
+
messageQueue,
|
|
33
|
+
statsService,
|
|
34
|
+
adminPassword: null,
|
|
35
|
+
heartbeatIntervalMs: 30_000,
|
|
36
|
+
heartbeatMaxMissed: 3,
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
app,
|
|
40
|
+
sessionStore,
|
|
41
|
+
authService,
|
|
42
|
+
connectionManager,
|
|
43
|
+
messageQueue,
|
|
44
|
+
cleanup: async () => {
|
|
45
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Helper to create a session and get a bearer token.
|
|
51
|
+
* Returns { sessionId, token } for use in subsequent requests.
|
|
52
|
+
*/
|
|
53
|
+
export async function createSessionAndGetToken(app, secret = "test-secret-12345") {
|
|
54
|
+
const res = await app.request("/api/sessions", {
|
|
55
|
+
method: "POST",
|
|
56
|
+
headers: { "Content-Type": "application/json" },
|
|
57
|
+
body: JSON.stringify({ secret }),
|
|
58
|
+
});
|
|
59
|
+
const body = (await res.json());
|
|
60
|
+
return { sessionId: body.sessionId, token: body.token };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Helper to register a peer in a session.
|
|
64
|
+
* Returns the PeerInfo response body.
|
|
65
|
+
*/
|
|
66
|
+
export async function registerPeer(app, sessionId, token, peerId, label = `Peer ${peerId}`) {
|
|
67
|
+
const res = await app.request(`/api/sessions/${sessionId}/peers`, {
|
|
68
|
+
method: "POST",
|
|
69
|
+
headers: {
|
|
70
|
+
"Content-Type": "application/json",
|
|
71
|
+
Authorization: `Bearer ${token}`,
|
|
72
|
+
},
|
|
73
|
+
body: JSON.stringify({
|
|
74
|
+
peerId,
|
|
75
|
+
cwd: `/home/${peerId}`,
|
|
76
|
+
label,
|
|
77
|
+
}),
|
|
78
|
+
});
|
|
79
|
+
return (await res.json());
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Create a test app backed by a real HTTP server on an ephemeral port.
|
|
83
|
+
* Required for WebSocket integration tests -- WS upgrade cannot work
|
|
84
|
+
* with Hono's app.request() testing mode.
|
|
85
|
+
*
|
|
86
|
+
* @param maxMessages - Message cap for the session store (default 500)
|
|
87
|
+
*/
|
|
88
|
+
export async function createTestWsApp(maxMessages = 500) {
|
|
89
|
+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "ws-test-"));
|
|
90
|
+
const sessionStore = new SessionStore(tmpDir, maxMessages);
|
|
91
|
+
const authService = new AuthService(4);
|
|
92
|
+
await sessionStore.init();
|
|
93
|
+
const connectionManager = new ConnectionManager(30_000);
|
|
94
|
+
const messageQueue = new MessageQueueService(sessionStore, 7 * 24 * 60 * 60 * 1000);
|
|
95
|
+
const startTime = Date.now();
|
|
96
|
+
const statsService = new StatsService(sessionStore, connectionManager, startTime);
|
|
97
|
+
const { app, injectWebSocket } = createApp({
|
|
98
|
+
sessionStore,
|
|
99
|
+
authService,
|
|
100
|
+
startTime,
|
|
101
|
+
maxMessages,
|
|
102
|
+
connectionManager,
|
|
103
|
+
messageQueue,
|
|
104
|
+
statsService,
|
|
105
|
+
adminPassword: null,
|
|
106
|
+
heartbeatIntervalMs: 30_000,
|
|
107
|
+
heartbeatMaxMissed: 3,
|
|
108
|
+
});
|
|
109
|
+
// Create real HTTP server on ephemeral port
|
|
110
|
+
const server = createAdaptorServer(app);
|
|
111
|
+
injectWebSocket(server);
|
|
112
|
+
return new Promise((resolve) => {
|
|
113
|
+
server.listen(0, () => {
|
|
114
|
+
const addr = server.address();
|
|
115
|
+
const port = typeof addr === "object" && addr ? addr.port : 0;
|
|
116
|
+
resolve({
|
|
117
|
+
app,
|
|
118
|
+
sessionStore,
|
|
119
|
+
authService,
|
|
120
|
+
connectionManager,
|
|
121
|
+
messageQueue,
|
|
122
|
+
server,
|
|
123
|
+
port,
|
|
124
|
+
wsUrl: (sessionId, token, peerId) => `ws://localhost:${port}/ws/${sessionId}?token=${encodeURIComponent(token)}&peerId=${encodeURIComponent(peerId)}`,
|
|
125
|
+
cleanup: async () => {
|
|
126
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
127
|
+
},
|
|
128
|
+
shutdown: async () => {
|
|
129
|
+
connectionManager.closeAll(1012, "Test shutdown");
|
|
130
|
+
return new Promise((res, rej) => {
|
|
131
|
+
server.close((err) => (err ? rej(err) : res()));
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/__tests__/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAGxD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAYtC;;;;;GAKG;AACH,MAA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