@bernierllc/chat-suite 1.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/.eslintrc.js +26 -0
- package/README.md +542 -0
- package/__tests__/integration/ChatSuite.test.ts +235 -0
- package/__tests__/unit/ConfigManager.test.ts +122 -0
- package/__tests__/unit/MessageOrchestrator.test.ts +223 -0
- package/__tests__/unit/UserManager.test.ts +208 -0
- package/dist/ChatSuite.d.ts +76 -0
- package/dist/ChatSuite.d.ts.map +1 -0
- package/dist/ChatSuite.js +273 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/neverhub/discovery.d.ts +40 -0
- package/dist/neverhub/discovery.d.ts.map +1 -0
- package/dist/neverhub/discovery.js +106 -0
- package/dist/neverhub/event-handlers.d.ts +38 -0
- package/dist/neverhub/event-handlers.d.ts.map +1 -0
- package/dist/neverhub/event-handlers.js +125 -0
- package/dist/neverhub/index.d.ts +4 -0
- package/dist/neverhub/index.d.ts.map +1 -0
- package/dist/neverhub/index.js +26 -0
- package/dist/neverhub/service-registration.d.ts +29 -0
- package/dist/neverhub/service-registration.d.ts.map +1 -0
- package/dist/neverhub/service-registration.js +66 -0
- package/dist/providers/ChatKitProvider.d.ts +53 -0
- package/dist/providers/ChatKitProvider.d.ts.map +1 -0
- package/dist/providers/ChatKitProvider.js +167 -0
- package/dist/providers/ExternalProviders.d.ts +101 -0
- package/dist/providers/ExternalProviders.d.ts.map +1 -0
- package/dist/providers/ExternalProviders.js +153 -0
- package/dist/providers/index.d.ts +3 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +25 -0
- package/dist/services/ConfigManager.d.ts +50 -0
- package/dist/services/ConfigManager.d.ts.map +1 -0
- package/dist/services/ConfigManager.js +95 -0
- package/dist/services/HealthMonitor.d.ts +58 -0
- package/dist/services/HealthMonitor.d.ts.map +1 -0
- package/dist/services/HealthMonitor.js +148 -0
- package/dist/services/MessageOrchestrator.d.ts +63 -0
- package/dist/services/MessageOrchestrator.d.ts.map +1 -0
- package/dist/services/MessageOrchestrator.js +212 -0
- package/dist/services/ProviderManager.d.ts +83 -0
- package/dist/services/ProviderManager.d.ts.map +1 -0
- package/dist/services/ProviderManager.js +204 -0
- package/dist/services/UserManager.d.ts +61 -0
- package/dist/services/UserManager.d.ts.map +1 -0
- package/dist/services/UserManager.js +141 -0
- package/dist/services/index.d.ts +6 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +28 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +26 -0
- package/dist/types/message-types.d.ts +80 -0
- package/dist/types/message-types.d.ts.map +1 -0
- package/dist/types/message-types.js +32 -0
- package/dist/types/provider-types.d.ts +96 -0
- package/dist/types/provider-types.d.ts.map +1 -0
- package/dist/types/provider-types.js +9 -0
- package/dist/types/suite-types.d.ts +101 -0
- package/dist/types/suite-types.d.ts.map +1 -0
- package/dist/types/suite-types.js +9 -0
- package/dist/utils/config-inheritance.d.ts +24 -0
- package/dist/utils/config-inheritance.d.ts.map +1 -0
- package/dist/utils/config-inheritance.js +167 -0
- package/dist/utils/error-handling.d.ts +37 -0
- package/dist/utils/error-handling.d.ts.map +1 -0
- package/dist/utils/error-handling.js +102 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +27 -0
- package/dist/utils/message-bridge.d.ts +68 -0
- package/dist/utils/message-bridge.d.ts.map +1 -0
- package/dist/utils/message-bridge.js +126 -0
- package/dist/utils/user-mapping.d.ts +63 -0
- package/dist/utils/user-mapping.d.ts.map +1 -0
- package/dist/utils/user-mapping.js +110 -0
- package/jest.config.cjs +30 -0
- package/package.json +67 -0
- package/src/ChatSuite.ts +347 -0
- package/src/index.ts +25 -0
- package/src/neverhub/discovery.ts +137 -0
- package/src/neverhub/event-handlers.ts +141 -0
- package/src/neverhub/index.ts +11 -0
- package/src/neverhub/service-registration.ts +89 -0
- package/src/providers/ChatKitProvider.ts +193 -0
- package/src/providers/ExternalProviders.ts +171 -0
- package/src/providers/index.ts +10 -0
- package/src/services/ConfigManager.ts +112 -0
- package/src/services/HealthMonitor.ts +169 -0
- package/src/services/MessageOrchestrator.ts +271 -0
- package/src/services/ProviderManager.ts +247 -0
- package/src/services/UserManager.ts +176 -0
- package/src/services/index.ts +13 -0
- package/src/types/index.ts +11 -0
- package/src/types/message-types.ts +94 -0
- package/src/types/provider-types.ts +116 -0
- package/src/types/suite-types.ts +117 -0
- package/src/utils/config-inheritance.ts +189 -0
- package/src/utils/error-handling.ts +114 -0
- package/src/utils/index.ts +12 -0
- package/src/utils/message-bridge.ts +164 -0
- package/src/utils/user-mapping.ts +132 -0
- package/tsconfig.json +31 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (c) 2025 Bernier LLC
|
|
4
|
+
|
|
5
|
+
This file is licensed to the client under a limited-use license.
|
|
6
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
7
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.UserMapper = void 0;
|
|
11
|
+
exports.createUnifiedId = createUnifiedId;
|
|
12
|
+
/**
|
|
13
|
+
* User mapping storage
|
|
14
|
+
*/
|
|
15
|
+
class UserMapper {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.identities = new Map();
|
|
18
|
+
this.providerIndex = new Map(); // provider:userId -> unifiedId
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create or update a user identity
|
|
22
|
+
*/
|
|
23
|
+
mapUser(identity) {
|
|
24
|
+
this.identities.set(identity.unifiedId, identity);
|
|
25
|
+
// Update provider index
|
|
26
|
+
identity.platformIds.forEach((platformUserId, provider) => {
|
|
27
|
+
const key = this.getProviderKey(provider, platformUserId);
|
|
28
|
+
this.providerIndex.set(key, identity.unifiedId);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get unified user ID from platform-specific ID
|
|
33
|
+
*/
|
|
34
|
+
getUnifiedId(provider, platformUserId) {
|
|
35
|
+
const key = this.getProviderKey(provider, platformUserId);
|
|
36
|
+
return this.providerIndex.get(key);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get platform-specific user ID from unified ID
|
|
40
|
+
*/
|
|
41
|
+
getPlatformId(unifiedId, provider) {
|
|
42
|
+
const identity = this.identities.get(unifiedId);
|
|
43
|
+
return identity?.platformIds.get(provider);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get full user identity
|
|
47
|
+
*/
|
|
48
|
+
getIdentity(unifiedId) {
|
|
49
|
+
return this.identities.get(unifiedId);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Add platform ID to existing user
|
|
53
|
+
*/
|
|
54
|
+
addPlatformId(unifiedId, provider, platformUserId) {
|
|
55
|
+
const identity = this.identities.get(unifiedId);
|
|
56
|
+
if (!identity) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
identity.platformIds.set(provider, platformUserId);
|
|
60
|
+
this.mapUser(identity);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Remove user identity
|
|
65
|
+
*/
|
|
66
|
+
removeUser(unifiedId) {
|
|
67
|
+
const identity = this.identities.get(unifiedId);
|
|
68
|
+
if (!identity) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
// Remove from provider index
|
|
72
|
+
identity.platformIds.forEach((platformUserId, provider) => {
|
|
73
|
+
const key = this.getProviderKey(provider, platformUserId);
|
|
74
|
+
this.providerIndex.delete(key);
|
|
75
|
+
});
|
|
76
|
+
return this.identities.delete(unifiedId);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get all users
|
|
80
|
+
*/
|
|
81
|
+
getAllUsers() {
|
|
82
|
+
return Array.from(this.identities.values());
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Clear all mappings
|
|
86
|
+
*/
|
|
87
|
+
clear() {
|
|
88
|
+
this.identities.clear();
|
|
89
|
+
this.providerIndex.clear();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get number of mapped users
|
|
93
|
+
*/
|
|
94
|
+
size() {
|
|
95
|
+
return this.identities.size;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Create provider key for indexing
|
|
99
|
+
*/
|
|
100
|
+
getProviderKey(provider, platformUserId) {
|
|
101
|
+
return `${provider}:${platformUserId}`;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.UserMapper = UserMapper;
|
|
105
|
+
/**
|
|
106
|
+
* Create a new unified user ID
|
|
107
|
+
*/
|
|
108
|
+
function createUnifiedId() {
|
|
109
|
+
return `user_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
110
|
+
}
|
package/jest.config.cjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2025 Bernier LLC
|
|
3
|
+
|
|
4
|
+
This file is licensed to the client under a limited-use license.
|
|
5
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
6
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
preset: 'ts-jest',
|
|
11
|
+
// Use fixed environment to handle Node.js v25+ localStorage issue
|
|
12
|
+
testEnvironment: '<rootDir>/../../../jest-environment-node-fixed.cjs',
|
|
13
|
+
roots: ['<rootDir>/__tests__'],
|
|
14
|
+
testMatch: ['**/__tests__/**/*.test.ts'],
|
|
15
|
+
collectCoverageFrom: [
|
|
16
|
+
'src/**/*.{ts,tsx}',
|
|
17
|
+
'!src/**/*.d.ts',
|
|
18
|
+
'!src/index.ts'
|
|
19
|
+
],
|
|
20
|
+
coverageThreshold: {
|
|
21
|
+
global: {
|
|
22
|
+
branches: 80,
|
|
23
|
+
functions: 80,
|
|
24
|
+
lines: 80,
|
|
25
|
+
statements: 80
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
coverageDirectory: 'coverage',
|
|
29
|
+
verbose: true
|
|
30
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bernierllc/chat-suite",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Comprehensive chat orchestration suite with AI-powered routing",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"chat",
|
|
9
|
+
"suite",
|
|
10
|
+
"orchestration",
|
|
11
|
+
"ai-routing",
|
|
12
|
+
"chatkit",
|
|
13
|
+
"slack",
|
|
14
|
+
"discord",
|
|
15
|
+
"teams",
|
|
16
|
+
"multi-provider"
|
|
17
|
+
],
|
|
18
|
+
"author": "Bernier LLC",
|
|
19
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"zod": "^3.22.0",
|
|
22
|
+
"@bernierllc/neverhub-adapter": "0.1.2",
|
|
23
|
+
"@bernierllc/chatkit-adapter": "1.0.0",
|
|
24
|
+
"@bernierllc/chat-ai-router": "1.0.0",
|
|
25
|
+
"@bernierllc/chat-analytics": "1.0.0"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {},
|
|
28
|
+
"peerDependenciesMeta": {
|
|
29
|
+
"@bernierllc/chat-integration-slack": {
|
|
30
|
+
"optional": true
|
|
31
|
+
},
|
|
32
|
+
"@bernierllc/chat-integration-discord": {
|
|
33
|
+
"optional": true
|
|
34
|
+
},
|
|
35
|
+
"@bernierllc/chat-integration-teams": {
|
|
36
|
+
"optional": true
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/jest": "^29.5.0",
|
|
41
|
+
"@types/node": "^20.0.0",
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
43
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
44
|
+
"eslint": "^8.0.0",
|
|
45
|
+
"jest": "^29.5.0",
|
|
46
|
+
"ts-jest": "^29.1.0",
|
|
47
|
+
"typescript": "^5.0.0"
|
|
48
|
+
},
|
|
49
|
+
"bernierllc": {
|
|
50
|
+
"category": "suite",
|
|
51
|
+
"integration": {
|
|
52
|
+
"neverhub": "required"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public",
|
|
57
|
+
"registry": "https://registry.npmjs.org/"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsc",
|
|
61
|
+
"test": "jest --watch",
|
|
62
|
+
"test:run": "jest --passWithNoTests",
|
|
63
|
+
"test:coverage": "jest --coverage --passWithNoTests",
|
|
64
|
+
"lint": "eslint src/**/*.ts",
|
|
65
|
+
"clean": "rm -rf dist"
|
|
66
|
+
}
|
|
67
|
+
}
|
package/src/ChatSuite.ts
ADDED
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2025 Bernier LLC
|
|
3
|
+
|
|
4
|
+
This file is licensed to the client under a limited-use license.
|
|
5
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
6
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { NeverHubAdapter } from '@bernierllc/neverhub-adapter';
|
|
10
|
+
import type {
|
|
11
|
+
ChatSuiteConfig,
|
|
12
|
+
SuiteInitResult,
|
|
13
|
+
ChatSuiteHealth,
|
|
14
|
+
BroadcastConfig,
|
|
15
|
+
ProviderMessage,
|
|
16
|
+
ProviderMessageResult,
|
|
17
|
+
SuiteResult,
|
|
18
|
+
Provider,
|
|
19
|
+
ProviderType
|
|
20
|
+
} from './types';
|
|
21
|
+
import { ConfigManager } from './services/ConfigManager';
|
|
22
|
+
import { UserManager } from './services/UserManager';
|
|
23
|
+
import { HealthMonitor } from './services/HealthMonitor';
|
|
24
|
+
import { ProviderManager } from './services/ProviderManager';
|
|
25
|
+
import { MessageOrchestrator } from './services/MessageOrchestrator';
|
|
26
|
+
import { ChatKitProvider } from './providers/ChatKitProvider';
|
|
27
|
+
import { MessageBridge } from './utils/message-bridge';
|
|
28
|
+
import { ChatSuiteError, ChatSuiteErrorType } from './utils/error-handling';
|
|
29
|
+
import {
|
|
30
|
+
registerWithNeverHub,
|
|
31
|
+
unregisterFromNeverHub,
|
|
32
|
+
updateHealthStatus,
|
|
33
|
+
discoverAllChatServices,
|
|
34
|
+
publishMessageEvent,
|
|
35
|
+
publishProviderEvent,
|
|
36
|
+
ChatSuiteEventType
|
|
37
|
+
} from './neverhub';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Main chat suite orchestration class
|
|
41
|
+
*/
|
|
42
|
+
export class ChatSuite {
|
|
43
|
+
private configManager: ConfigManager;
|
|
44
|
+
private userManager: UserManager;
|
|
45
|
+
private healthMonitor: HealthMonitor;
|
|
46
|
+
private providerManager: ProviderManager;
|
|
47
|
+
private messageOrchestrator: MessageOrchestrator;
|
|
48
|
+
|
|
49
|
+
private neverhubAdapter?: NeverHubAdapter;
|
|
50
|
+
private neverhubConnected = false;
|
|
51
|
+
private initialized = false;
|
|
52
|
+
|
|
53
|
+
constructor(config?: Partial<ChatSuiteConfig>) {
|
|
54
|
+
this.configManager = new ConfigManager(config);
|
|
55
|
+
this.userManager = new UserManager();
|
|
56
|
+
this.healthMonitor = new HealthMonitor();
|
|
57
|
+
this.providerManager = new ProviderManager();
|
|
58
|
+
this.messageOrchestrator = new MessageOrchestrator();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Initialize the chat suite
|
|
63
|
+
*/
|
|
64
|
+
public async initialize(): Promise<SuiteInitResult> {
|
|
65
|
+
try {
|
|
66
|
+
const config = this.configManager.getConfig();
|
|
67
|
+
|
|
68
|
+
// 1. Initialize NeverHub (if enabled)
|
|
69
|
+
if (config.neverhub?.enabled) {
|
|
70
|
+
await this.initializeNeverHub();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 2. Initialize ChatKit provider (always required)
|
|
74
|
+
const chatKitResult = await this.initializeChatKitProvider(config);
|
|
75
|
+
if (!chatKitResult.success) {
|
|
76
|
+
throw new ChatSuiteError(
|
|
77
|
+
ChatSuiteErrorType.INITIALIZATION_ERROR,
|
|
78
|
+
`Failed to initialize ChatKit: ${chatKitResult.error}`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 3. Initialize message bridge (if configured)
|
|
83
|
+
if (config.messageBridge) {
|
|
84
|
+
const bridge = new MessageBridge(config.messageBridge);
|
|
85
|
+
this.messageOrchestrator.setMessageBridge(bridge);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 4. Start health monitoring
|
|
89
|
+
this.healthMonitor.startMonitoring(60000);
|
|
90
|
+
|
|
91
|
+
// 5. Update NeverHub health status
|
|
92
|
+
if (this.neverhubConnected && this.neverhubAdapter) {
|
|
93
|
+
await updateHealthStatus(this.neverhubAdapter, 'healthy', {
|
|
94
|
+
providersInitialized: this.providerManager.getProviderCount().initialized
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
this.initialized = true;
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
success: true,
|
|
102
|
+
providersInitialized: this.getInitializedProviderTypes(),
|
|
103
|
+
providersFailed: [],
|
|
104
|
+
aiRoutingEnabled: config.aiRouting?.enabled || false,
|
|
105
|
+
analyticsEnabled: config.analytics?.enabled || false,
|
|
106
|
+
neverhubConnected: this.neverhubConnected
|
|
107
|
+
};
|
|
108
|
+
} catch (error) {
|
|
109
|
+
return {
|
|
110
|
+
success: false,
|
|
111
|
+
providersInitialized: [],
|
|
112
|
+
providersFailed: ['chatkit'],
|
|
113
|
+
aiRoutingEnabled: false,
|
|
114
|
+
analyticsEnabled: false,
|
|
115
|
+
neverhubConnected: false,
|
|
116
|
+
error: error instanceof Error ? error.message : 'Initialization failed'
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Initialize NeverHub connection
|
|
123
|
+
*/
|
|
124
|
+
private async initializeNeverHub(): Promise<void> {
|
|
125
|
+
try {
|
|
126
|
+
const detected = await NeverHubAdapter.detect();
|
|
127
|
+
if (!detected) {
|
|
128
|
+
console.log('⚠️ NeverHub not available - running without service discovery');
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
this.neverhubAdapter = new NeverHubAdapter();
|
|
133
|
+
const config = this.configManager.getConfig();
|
|
134
|
+
|
|
135
|
+
if (config.neverhub) {
|
|
136
|
+
const registered = await registerWithNeverHub(this.neverhubAdapter, config.neverhub);
|
|
137
|
+
if (registered) {
|
|
138
|
+
this.neverhubConnected = true;
|
|
139
|
+
|
|
140
|
+
// Discover available services
|
|
141
|
+
const discovered = await discoverAllChatServices(this.neverhubAdapter);
|
|
142
|
+
console.log(`✅ Discovered services:`, {
|
|
143
|
+
providers: discovered.providers.length,
|
|
144
|
+
aiRouter: !!discovered.aiRouter,
|
|
145
|
+
analytics: !!discovered.analytics
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.error('❌ NeverHub initialization failed (continuing without):', error);
|
|
151
|
+
this.neverhubConnected = false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Initialize ChatKit provider
|
|
157
|
+
*/
|
|
158
|
+
private async initializeChatKitProvider(config: ChatSuiteConfig): Promise<SuiteResult<void>> {
|
|
159
|
+
try {
|
|
160
|
+
const chatKitConfig = config.providers.chatkit;
|
|
161
|
+
if (!chatKitConfig || !chatKitConfig.enabled) {
|
|
162
|
+
return {
|
|
163
|
+
success: false,
|
|
164
|
+
error: 'ChatKit provider is not enabled in configuration'
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const provider = new ChatKitProvider({
|
|
169
|
+
serviceName: chatKitConfig.config.serviceName as string,
|
|
170
|
+
features: chatKitConfig.config.features as string[],
|
|
171
|
+
config: chatKitConfig.config
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// Register provider
|
|
175
|
+
const registerResult = this.providerManager.registerProvider({
|
|
176
|
+
provider,
|
|
177
|
+
priority: chatKitConfig.priority,
|
|
178
|
+
enabled: chatKitConfig.enabled
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
if (!registerResult.success) {
|
|
182
|
+
return registerResult;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Initialize provider
|
|
186
|
+
const initResult = await this.providerManager.initializeProvider('chatkit');
|
|
187
|
+
if (!initResult.success) {
|
|
188
|
+
return initResult;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Register with health monitor
|
|
192
|
+
this.healthMonitor.registerProvider(provider);
|
|
193
|
+
|
|
194
|
+
// Publish provider initialized event
|
|
195
|
+
if (this.neverhubConnected && this.neverhubAdapter) {
|
|
196
|
+
await publishProviderEvent(
|
|
197
|
+
this.neverhubAdapter,
|
|
198
|
+
ChatSuiteEventType.PROVIDER_INITIALIZED,
|
|
199
|
+
'chatkit'
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return { success: true };
|
|
204
|
+
} catch (error) {
|
|
205
|
+
return {
|
|
206
|
+
success: false,
|
|
207
|
+
error: error instanceof Error ? error.message : 'Failed to initialize ChatKit'
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Send a message through a specific provider
|
|
214
|
+
*/
|
|
215
|
+
public async sendMessage(
|
|
216
|
+
providerType: ProviderType,
|
|
217
|
+
message: ProviderMessage
|
|
218
|
+
): Promise<SuiteResult<ProviderMessageResult>> {
|
|
219
|
+
if (!this.initialized) {
|
|
220
|
+
return {
|
|
221
|
+
success: false,
|
|
222
|
+
error: 'Chat suite is not initialized'
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const provider = this.providerManager.getProvider(providerType);
|
|
227
|
+
if (!provider) {
|
|
228
|
+
return {
|
|
229
|
+
success: false,
|
|
230
|
+
error: `Provider ${providerType} not found`
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const result = await this.messageOrchestrator.sendMessage(provider, message);
|
|
235
|
+
|
|
236
|
+
// Publish message event
|
|
237
|
+
if (this.neverhubConnected && this.neverhubAdapter && result.success && result.data) {
|
|
238
|
+
await publishMessageEvent(this.neverhubAdapter, {
|
|
239
|
+
type: 'message.sent',
|
|
240
|
+
messageId: result.data.messageId || 'unknown',
|
|
241
|
+
provider: providerType,
|
|
242
|
+
timestamp: new Date(),
|
|
243
|
+
data: { content: message.content }
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return result;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Broadcast a message to multiple providers
|
|
252
|
+
*/
|
|
253
|
+
public async broadcastMessage(
|
|
254
|
+
config: BroadcastConfig
|
|
255
|
+
): Promise<SuiteResult<ProviderMessageResult[]>> {
|
|
256
|
+
if (!this.initialized) {
|
|
257
|
+
return {
|
|
258
|
+
success: false,
|
|
259
|
+
error: 'Chat suite is not initialized'
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const providers = new Map<ProviderType, Provider>();
|
|
264
|
+
|
|
265
|
+
for (const type of config.platforms) {
|
|
266
|
+
const provider = this.providerManager.getProvider(type);
|
|
267
|
+
if (provider && this.providerManager.isInitialized(type)) {
|
|
268
|
+
providers.set(type, provider);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return this.messageOrchestrator.broadcastMessage(providers, config);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Get health status
|
|
277
|
+
*/
|
|
278
|
+
public async getHealth(): Promise<ChatSuiteHealth> {
|
|
279
|
+
return this.healthMonitor.checkHealth();
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Get user manager
|
|
284
|
+
*/
|
|
285
|
+
public getUserManager(): UserManager {
|
|
286
|
+
return this.userManager;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Get config manager
|
|
291
|
+
*/
|
|
292
|
+
public getConfigManager(): ConfigManager {
|
|
293
|
+
return this.configManager;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Check if initialized
|
|
298
|
+
*/
|
|
299
|
+
public isInitialized(): boolean {
|
|
300
|
+
return this.initialized;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Check if NeverHub is connected
|
|
305
|
+
*/
|
|
306
|
+
public isNeverHubConnected(): boolean {
|
|
307
|
+
return this.neverhubConnected;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Get provider manager
|
|
312
|
+
*/
|
|
313
|
+
public getProviderManager(): ProviderManager {
|
|
314
|
+
return this.providerManager;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Get message orchestrator
|
|
319
|
+
*/
|
|
320
|
+
public getMessageOrchestrator(): MessageOrchestrator {
|
|
321
|
+
return this.messageOrchestrator;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Shutdown the chat suite
|
|
326
|
+
*/
|
|
327
|
+
public async shutdown(): Promise<void> {
|
|
328
|
+
this.healthMonitor.stopMonitoring();
|
|
329
|
+
await this.providerManager.shutdownAll();
|
|
330
|
+
|
|
331
|
+
if (this.neverhubConnected && this.neverhubAdapter) {
|
|
332
|
+
await unregisterFromNeverHub(this.neverhubAdapter);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
this.initialized = false;
|
|
336
|
+
this.neverhubConnected = false;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Get initialized provider types
|
|
341
|
+
*/
|
|
342
|
+
private getInitializedProviderTypes(): ProviderType[] {
|
|
343
|
+
return this.providerManager
|
|
344
|
+
.getInitializedProviders()
|
|
345
|
+
.map(p => p.type);
|
|
346
|
+
}
|
|
347
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2025 Bernier LLC
|
|
3
|
+
|
|
4
|
+
This file is licensed to the client under a limited-use license.
|
|
5
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
6
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Main export
|
|
10
|
+
export { ChatSuite } from './ChatSuite';
|
|
11
|
+
|
|
12
|
+
// Types
|
|
13
|
+
export * from './types';
|
|
14
|
+
|
|
15
|
+
// Services
|
|
16
|
+
export * from './services';
|
|
17
|
+
|
|
18
|
+
// Providers
|
|
19
|
+
export * from './providers';
|
|
20
|
+
|
|
21
|
+
// Utilities
|
|
22
|
+
export * from './utils';
|
|
23
|
+
|
|
24
|
+
// NeverHub integration
|
|
25
|
+
export * from './neverhub';
|