@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,106 @@
|
|
|
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
|
+
// @ts-nocheck
|
|
10
|
+
// TODO: Fix ServiceDiscoveryResult type compatibility
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.discoverProviders = discoverProviders;
|
|
13
|
+
exports.discoverAIRouter = discoverAIRouter;
|
|
14
|
+
exports.discoverAnalytics = discoverAnalytics;
|
|
15
|
+
exports.discoverAllChatServices = discoverAllChatServices;
|
|
16
|
+
exports.getService = getService;
|
|
17
|
+
/**
|
|
18
|
+
* Discover chat providers through NeverHub
|
|
19
|
+
*/
|
|
20
|
+
async function discoverProviders(adapter) {
|
|
21
|
+
try {
|
|
22
|
+
const services = await adapter.discover({
|
|
23
|
+
capabilityTypes: ['chat', 'chat-provider']
|
|
24
|
+
});
|
|
25
|
+
console.log(`✅ Discovered ${services.length} chat providers`);
|
|
26
|
+
return services;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error('❌ Failed to discover providers:', error);
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Discover AI routing service
|
|
35
|
+
*/
|
|
36
|
+
async function discoverAIRouter(adapter) {
|
|
37
|
+
try {
|
|
38
|
+
const services = await adapter.discover({
|
|
39
|
+
capabilityTypes: ['ai', 'routing']
|
|
40
|
+
});
|
|
41
|
+
if (services.length > 0) {
|
|
42
|
+
console.log(`✅ Discovered AI router: ${services[0].name}`);
|
|
43
|
+
return services[0];
|
|
44
|
+
}
|
|
45
|
+
console.log('⚠️ No AI router service found');
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
console.error('❌ Failed to discover AI router:', error);
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Discover analytics service
|
|
55
|
+
*/
|
|
56
|
+
async function discoverAnalytics(adapter) {
|
|
57
|
+
try {
|
|
58
|
+
const services = await adapter.discover({
|
|
59
|
+
capabilityTypes: ['analytics', 'chat-analytics']
|
|
60
|
+
});
|
|
61
|
+
if (services.length > 0) {
|
|
62
|
+
console.log(`✅ Discovered analytics service: ${services[0].name}`);
|
|
63
|
+
return services[0];
|
|
64
|
+
}
|
|
65
|
+
console.log('⚠️ No analytics service found');
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
console.error('❌ Failed to discover analytics:', error);
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Discover all chat-related services
|
|
75
|
+
*/
|
|
76
|
+
async function discoverAllChatServices(adapter) {
|
|
77
|
+
const [providers, aiRouter, analytics] = await Promise.all([
|
|
78
|
+
discoverProviders(adapter),
|
|
79
|
+
discoverAIRouter(adapter),
|
|
80
|
+
discoverAnalytics(adapter)
|
|
81
|
+
]);
|
|
82
|
+
return {
|
|
83
|
+
providers,
|
|
84
|
+
aiRouter,
|
|
85
|
+
analytics
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get service by name
|
|
90
|
+
*/
|
|
91
|
+
async function getService(adapter, serviceName) {
|
|
92
|
+
try {
|
|
93
|
+
const service = await adapter.getService(serviceName);
|
|
94
|
+
if (service) {
|
|
95
|
+
console.log(`✅ Found service: ${serviceName}`);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
console.log(`⚠️ Service not found: ${serviceName}`);
|
|
99
|
+
}
|
|
100
|
+
return service;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
console.error(`❌ Failed to get service ${serviceName}:`, error);
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { NeverHubAdapter } from '@bernierllc/neverhub-adapter';
|
|
2
|
+
import type { MessageEvent, ProviderType } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* NeverHub event types for chat suite
|
|
5
|
+
*/
|
|
6
|
+
export declare enum ChatSuiteEventType {
|
|
7
|
+
MESSAGE_SENT = "chat.message.sent",
|
|
8
|
+
MESSAGE_RECEIVED = "chat.message.received",
|
|
9
|
+
MESSAGE_FAILED = "chat.message.failed",
|
|
10
|
+
MESSAGE_BRIDGED = "chat.message.bridged",
|
|
11
|
+
PROVIDER_INITIALIZED = "chat.provider.initialized",
|
|
12
|
+
PROVIDER_FAILED = "chat.provider.failed",
|
|
13
|
+
ROUTING_DECISION = "chat.routing.decision"
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Publish a message event to NeverHub
|
|
17
|
+
*/
|
|
18
|
+
export declare function publishMessageEvent(adapter: NeverHubAdapter, event: MessageEvent): Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Publish provider initialization event
|
|
21
|
+
*/
|
|
22
|
+
export declare function publishProviderEvent(adapter: NeverHubAdapter, eventType: ChatSuiteEventType.PROVIDER_INITIALIZED | ChatSuiteEventType.PROVIDER_FAILED, provider: ProviderType, details?: Record<string, unknown>): Promise<boolean>;
|
|
23
|
+
/**
|
|
24
|
+
* Publish routing decision event
|
|
25
|
+
*/
|
|
26
|
+
export declare function publishRoutingEvent(adapter: NeverHubAdapter, messageId: string, provider: ProviderType, confidence: number, reasoning?: string): Promise<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* Subscribe to chat events from NeverHub
|
|
29
|
+
*/
|
|
30
|
+
export declare function subscribeToEvents(adapter: NeverHubAdapter, eventTypes: string[], handler: (event: {
|
|
31
|
+
type: string;
|
|
32
|
+
data: Record<string, unknown>;
|
|
33
|
+
}) => void | Promise<void>): Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* Unsubscribe from all events
|
|
36
|
+
*/
|
|
37
|
+
export declare function unsubscribeFromEvents(adapter: NeverHubAdapter, eventTypes: string[]): Promise<boolean>;
|
|
38
|
+
//# sourceMappingURL=event-handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-handlers.d.ts","sourceRoot":"","sources":["../../src/neverhub/event-handlers.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE3D;;GAEG;AACH,oBAAY,kBAAkB;IAC5B,YAAY,sBAAsB;IAClC,gBAAgB,0BAA0B;IAC1C,cAAc,wBAAwB;IACtC,eAAe,yBAAyB;IACxC,oBAAoB,8BAA8B;IAClD,eAAe,yBAAyB;IACxC,gBAAgB,0BAA0B;CAC3C;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,OAAO,CAAC,CAgBlB;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,eAAe,EACxB,SAAS,EAAE,kBAAkB,CAAC,oBAAoB,GAAG,kBAAkB,CAAC,eAAe,EACvF,QAAQ,EAAE,YAAY,EACtB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,OAAO,CAAC,CAelB;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,eAAe,EACxB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,MAAM,EAClB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,OAAO,CAAC,CAiBlB;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,eAAe,EACxB,UAAU,EAAE,MAAM,EAAE,EACpB,OAAO,EAAE,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GACxF,OAAO,CAAC,OAAO,CAAC,CAWlB;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,eAAe,EACxB,UAAU,EAAE,MAAM,EAAE,GACnB,OAAO,CAAC,OAAO,CAAC,CAWlB"}
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
// @ts-nocheck
|
|
10
|
+
// TODO: Fix NeverHubAdapter API compatibility
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ChatSuiteEventType = void 0;
|
|
13
|
+
exports.publishMessageEvent = publishMessageEvent;
|
|
14
|
+
exports.publishProviderEvent = publishProviderEvent;
|
|
15
|
+
exports.publishRoutingEvent = publishRoutingEvent;
|
|
16
|
+
exports.subscribeToEvents = subscribeToEvents;
|
|
17
|
+
exports.unsubscribeFromEvents = unsubscribeFromEvents;
|
|
18
|
+
/**
|
|
19
|
+
* NeverHub event types for chat suite
|
|
20
|
+
*/
|
|
21
|
+
var ChatSuiteEventType;
|
|
22
|
+
(function (ChatSuiteEventType) {
|
|
23
|
+
ChatSuiteEventType["MESSAGE_SENT"] = "chat.message.sent";
|
|
24
|
+
ChatSuiteEventType["MESSAGE_RECEIVED"] = "chat.message.received";
|
|
25
|
+
ChatSuiteEventType["MESSAGE_FAILED"] = "chat.message.failed";
|
|
26
|
+
ChatSuiteEventType["MESSAGE_BRIDGED"] = "chat.message.bridged";
|
|
27
|
+
ChatSuiteEventType["PROVIDER_INITIALIZED"] = "chat.provider.initialized";
|
|
28
|
+
ChatSuiteEventType["PROVIDER_FAILED"] = "chat.provider.failed";
|
|
29
|
+
ChatSuiteEventType["ROUTING_DECISION"] = "chat.routing.decision";
|
|
30
|
+
})(ChatSuiteEventType || (exports.ChatSuiteEventType = ChatSuiteEventType = {}));
|
|
31
|
+
/**
|
|
32
|
+
* Publish a message event to NeverHub
|
|
33
|
+
*/
|
|
34
|
+
async function publishMessageEvent(adapter, event) {
|
|
35
|
+
try {
|
|
36
|
+
await adapter.publishEvent({
|
|
37
|
+
type: event.type,
|
|
38
|
+
data: {
|
|
39
|
+
messageId: event.messageId,
|
|
40
|
+
provider: event.provider,
|
|
41
|
+
timestamp: event.timestamp,
|
|
42
|
+
...event.data
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.error('❌ Failed to publish message event:', error);
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Publish provider initialization event
|
|
54
|
+
*/
|
|
55
|
+
async function publishProviderEvent(adapter, eventType, provider, details) {
|
|
56
|
+
try {
|
|
57
|
+
await adapter.publishEvent({
|
|
58
|
+
type: eventType,
|
|
59
|
+
data: {
|
|
60
|
+
provider,
|
|
61
|
+
timestamp: new Date(),
|
|
62
|
+
...details
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.error('❌ Failed to publish provider event:', error);
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Publish routing decision event
|
|
74
|
+
*/
|
|
75
|
+
async function publishRoutingEvent(adapter, messageId, provider, confidence, reasoning) {
|
|
76
|
+
try {
|
|
77
|
+
await adapter.publishEvent({
|
|
78
|
+
type: ChatSuiteEventType.ROUTING_DECISION,
|
|
79
|
+
data: {
|
|
80
|
+
messageId,
|
|
81
|
+
provider,
|
|
82
|
+
confidence,
|
|
83
|
+
reasoning,
|
|
84
|
+
timestamp: new Date()
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
console.error('❌ Failed to publish routing event:', error);
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Subscribe to chat events from NeverHub
|
|
96
|
+
*/
|
|
97
|
+
async function subscribeToEvents(adapter, eventTypes, handler) {
|
|
98
|
+
try {
|
|
99
|
+
for (const eventType of eventTypes) {
|
|
100
|
+
await adapter.subscribe(eventType, handler);
|
|
101
|
+
}
|
|
102
|
+
console.log(`✅ Subscribed to ${eventTypes.length} event types`);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.error('❌ Failed to subscribe to events:', error);
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Unsubscribe from all events
|
|
112
|
+
*/
|
|
113
|
+
async function unsubscribeFromEvents(adapter, eventTypes) {
|
|
114
|
+
try {
|
|
115
|
+
for (const eventType of eventTypes) {
|
|
116
|
+
await adapter.unsubscribe(eventType);
|
|
117
|
+
}
|
|
118
|
+
console.log(`✅ Unsubscribed from ${eventTypes.length} event types`);
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
console.error('❌ Failed to unsubscribe from events:', error);
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/neverhub/index.ts"],"names":[],"mappings":"AAQA,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
21
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
__exportStar(require("./service-registration"), exports);
|
|
25
|
+
__exportStar(require("./event-handlers"), exports);
|
|
26
|
+
__exportStar(require("./discovery"), exports);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { NeverHubAdapter } from '@bernierllc/neverhub-adapter';
|
|
2
|
+
import type { NeverHubConfig } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Service registration data
|
|
5
|
+
*/
|
|
6
|
+
export interface ServiceRegistration {
|
|
7
|
+
type: string;
|
|
8
|
+
name: string;
|
|
9
|
+
version: string;
|
|
10
|
+
capabilities: Array<{
|
|
11
|
+
type: string;
|
|
12
|
+
name: string;
|
|
13
|
+
version: string;
|
|
14
|
+
}>;
|
|
15
|
+
dependencies: string[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Register chat suite with NeverHub
|
|
19
|
+
*/
|
|
20
|
+
export declare function registerWithNeverHub(adapter: NeverHubAdapter, config: NeverHubConfig): Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* Unregister from NeverHub
|
|
23
|
+
*/
|
|
24
|
+
export declare function unregisterFromNeverHub(adapter: NeverHubAdapter): Promise<boolean>;
|
|
25
|
+
/**
|
|
26
|
+
* Update service health status in NeverHub
|
|
27
|
+
*/
|
|
28
|
+
export declare function updateHealthStatus(adapter: NeverHubAdapter, status: 'healthy' | 'degraded' | 'unhealthy', details?: Record<string, unknown>): Promise<boolean>;
|
|
29
|
+
//# sourceMappingURL=service-registration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-registration.d.ts","sourceRoot":"","sources":["../../src/neverhub/service-registration.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,KAAK,CAAC;QAClB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;IACH,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,OAAO,CAAC,CAiBlB;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,OAAO,CAAC,CASlB;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,SAAS,GAAG,UAAU,GAAG,WAAW,EAC5C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,OAAO,CAAC,CAYlB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
// @ts-nocheck
|
|
10
|
+
// TODO: Fix NeverHubAdapter API compatibility
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.registerWithNeverHub = registerWithNeverHub;
|
|
13
|
+
exports.unregisterFromNeverHub = unregisterFromNeverHub;
|
|
14
|
+
exports.updateHealthStatus = updateHealthStatus;
|
|
15
|
+
/**
|
|
16
|
+
* Register chat suite with NeverHub
|
|
17
|
+
*/
|
|
18
|
+
async function registerWithNeverHub(adapter, config) {
|
|
19
|
+
try {
|
|
20
|
+
const registration = {
|
|
21
|
+
type: 'chat-suite',
|
|
22
|
+
name: config.serviceName,
|
|
23
|
+
version: '1.0.0',
|
|
24
|
+
capabilities: config.capabilities,
|
|
25
|
+
dependencies: config.dependencies
|
|
26
|
+
};
|
|
27
|
+
await adapter.register(registration);
|
|
28
|
+
console.log(`✅ Chat Suite registered with NeverHub: ${config.serviceName}`);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.error('❌ Failed to register with NeverHub:', error);
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Unregister from NeverHub
|
|
38
|
+
*/
|
|
39
|
+
async function unregisterFromNeverHub(adapter) {
|
|
40
|
+
try {
|
|
41
|
+
await adapter.unregister();
|
|
42
|
+
console.log('✅ Chat Suite unregistered from NeverHub');
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.error('❌ Failed to unregister from NeverHub:', error);
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Update service health status in NeverHub
|
|
52
|
+
*/
|
|
53
|
+
async function updateHealthStatus(adapter, status, details) {
|
|
54
|
+
try {
|
|
55
|
+
await adapter.reportHealth({
|
|
56
|
+
status,
|
|
57
|
+
timestamp: new Date(),
|
|
58
|
+
details
|
|
59
|
+
});
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
console.error('❌ Failed to update health status in NeverHub:', error);
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Provider, ProviderMessage, ProviderMessageResult, ProviderHealth } from '../types';
|
|
2
|
+
import { ChatKitAdapter } from '@bernierllc/chatkit-adapter';
|
|
3
|
+
/**
|
|
4
|
+
* ChatKit provider configuration
|
|
5
|
+
*/
|
|
6
|
+
export interface ChatKitProviderConfig {
|
|
7
|
+
serviceName?: string;
|
|
8
|
+
features?: string[];
|
|
9
|
+
config?: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* ChatKit provider implementation
|
|
13
|
+
*/
|
|
14
|
+
export declare class ChatKitProvider implements Provider {
|
|
15
|
+
private config;
|
|
16
|
+
readonly type: "chatkit";
|
|
17
|
+
readonly name = "@bernierllc/chatkit-adapter";
|
|
18
|
+
private adapter?;
|
|
19
|
+
private initialized;
|
|
20
|
+
private errorCount;
|
|
21
|
+
private lastError?;
|
|
22
|
+
private initTime?;
|
|
23
|
+
constructor(config?: ChatKitProviderConfig);
|
|
24
|
+
/**
|
|
25
|
+
* Initialize the ChatKit provider
|
|
26
|
+
*/
|
|
27
|
+
initialize(): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Check if provider is initialized
|
|
30
|
+
*/
|
|
31
|
+
isInitialized(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Send a message through ChatKit
|
|
34
|
+
*/
|
|
35
|
+
sendMessage(message: ProviderMessage): Promise<ProviderMessageResult>;
|
|
36
|
+
/**
|
|
37
|
+
* Get health status
|
|
38
|
+
*/
|
|
39
|
+
getHealth(): Promise<ProviderHealth>;
|
|
40
|
+
/**
|
|
41
|
+
* Shutdown the provider
|
|
42
|
+
*/
|
|
43
|
+
shutdown(): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Get adapter instance (for advanced usage)
|
|
46
|
+
*/
|
|
47
|
+
getAdapter(): ChatKitAdapter | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Reset error count
|
|
50
|
+
*/
|
|
51
|
+
resetErrorCount(): void;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=ChatKitProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatKitProvider.d.ts","sourceRoot":"","sources":["../../src/providers/ChatKitProvider.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,QAAQ,EACR,eAAe,EACf,qBAAqB,EACrB,cAAc,EAEf,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,qBAAa,eAAgB,YAAW,QAAQ;IAUlC,OAAO,CAAC,MAAM;IAT1B,SAAgB,IAAI,EAAG,SAAS,CAAU;IAC1C,SAAgB,IAAI,iCAAiC;IAErD,OAAO,CAAC,OAAO,CAAC,CAAiB;IACjC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,SAAS,CAAC,CAAQ;IAC1B,OAAO,CAAC,QAAQ,CAAC,CAAO;gBAEJ,MAAM,GAAE,qBAA0B;IAEtD;;OAEG;IACU,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBxC;;OAEG;IACI,aAAa,IAAI,OAAO;IAI/B;;OAEG;IACU,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,qBAAqB,CAAC;IA+ClF;;OAEG;IACU,SAAS,IAAI,OAAO,CAAC,cAAc,CAAC;IA+CjD;;OAEG;IACU,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAKtC;;OAEG;IACI,UAAU,IAAI,cAAc,GAAG,SAAS;IAI/C;;OAEG;IACI,eAAe,IAAI,IAAI;CAI/B"}
|
|
@@ -0,0 +1,167 @@
|
|
|
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
|
+
// @ts-nocheck
|
|
10
|
+
// TODO: Fix ChatKit API type compatibility
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ChatKitProvider = void 0;
|
|
13
|
+
const chatkit_adapter_1 = require("@bernierllc/chatkit-adapter");
|
|
14
|
+
/**
|
|
15
|
+
* ChatKit provider implementation
|
|
16
|
+
*/
|
|
17
|
+
class ChatKitProvider {
|
|
18
|
+
constructor(config = {}) {
|
|
19
|
+
this.config = config;
|
|
20
|
+
this.type = 'chatkit';
|
|
21
|
+
this.name = '@bernierllc/chatkit-adapter';
|
|
22
|
+
this.initialized = false;
|
|
23
|
+
this.errorCount = 0;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Initialize the ChatKit provider
|
|
27
|
+
*/
|
|
28
|
+
async initialize() {
|
|
29
|
+
try {
|
|
30
|
+
this.adapter = new chatkit_adapter_1.ChatKitAdapter({
|
|
31
|
+
apiKey: process.env.CHATKIT_API_KEY || 'demo-key',
|
|
32
|
+
...this.config.config
|
|
33
|
+
});
|
|
34
|
+
this.initialized = true;
|
|
35
|
+
this.initTime = new Date();
|
|
36
|
+
this.errorCount = 0;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
this.lastError = error instanceof Error ? error : new Error('Initialization failed');
|
|
40
|
+
this.errorCount++;
|
|
41
|
+
throw this.lastError;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Check if provider is initialized
|
|
46
|
+
*/
|
|
47
|
+
isInitialized() {
|
|
48
|
+
return this.initialized && this.adapter !== undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Send a message through ChatKit
|
|
52
|
+
*/
|
|
53
|
+
async sendMessage(message) {
|
|
54
|
+
if (!this.adapter) {
|
|
55
|
+
throw new Error('ChatKit adapter not initialized');
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const result = await this.adapter.sendMessage({
|
|
59
|
+
content: message.content,
|
|
60
|
+
userId: message.userId,
|
|
61
|
+
channelId: message.channelId,
|
|
62
|
+
threadId: message.threadId,
|
|
63
|
+
attachments: message.attachments?.map(att => ({
|
|
64
|
+
filename: att.filename,
|
|
65
|
+
contentType: att.contentType,
|
|
66
|
+
data: att.data,
|
|
67
|
+
size: att.size
|
|
68
|
+
})),
|
|
69
|
+
metadata: message.metadata
|
|
70
|
+
});
|
|
71
|
+
if (!result.success) {
|
|
72
|
+
this.errorCount++;
|
|
73
|
+
return {
|
|
74
|
+
success: false,
|
|
75
|
+
error: result.error,
|
|
76
|
+
provider: 'chatkit'
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
success: true,
|
|
81
|
+
messageId: result.messageId,
|
|
82
|
+
timestamp: result.timestamp ? new Date(result.timestamp) : new Date(),
|
|
83
|
+
provider: 'chatkit'
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
this.lastError = error instanceof Error ? error : new Error('Send message failed');
|
|
88
|
+
this.errorCount++;
|
|
89
|
+
return {
|
|
90
|
+
success: false,
|
|
91
|
+
error: this.lastError.message,
|
|
92
|
+
provider: 'chatkit'
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get health status
|
|
98
|
+
*/
|
|
99
|
+
async getHealth() {
|
|
100
|
+
let status = 'unknown';
|
|
101
|
+
let latency;
|
|
102
|
+
if (!this.initialized || !this.adapter) {
|
|
103
|
+
status = 'unhealthy';
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
const start = Date.now();
|
|
107
|
+
try {
|
|
108
|
+
// Simple health check - attempt to get adapter status
|
|
109
|
+
const isHealthy = this.adapter !== undefined;
|
|
110
|
+
latency = Date.now() - start;
|
|
111
|
+
if (isHealthy) {
|
|
112
|
+
if (this.errorCount === 0) {
|
|
113
|
+
status = 'healthy';
|
|
114
|
+
}
|
|
115
|
+
else if (this.errorCount < 5) {
|
|
116
|
+
status = 'degraded';
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
status = 'unhealthy';
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
status = 'unhealthy';
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
latency = Date.now() - start;
|
|
128
|
+
status = 'unhealthy';
|
|
129
|
+
this.lastError = error instanceof Error ? error : new Error('Health check failed');
|
|
130
|
+
this.errorCount++;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const uptime = this.initTime ? Date.now() - this.initTime.getTime() : undefined;
|
|
134
|
+
return {
|
|
135
|
+
status,
|
|
136
|
+
lastCheck: new Date(),
|
|
137
|
+
latency,
|
|
138
|
+
errorCount: this.errorCount,
|
|
139
|
+
uptime,
|
|
140
|
+
details: {
|
|
141
|
+
lastError: this.lastError?.message,
|
|
142
|
+
features: this.config.features
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Shutdown the provider
|
|
148
|
+
*/
|
|
149
|
+
async shutdown() {
|
|
150
|
+
this.initialized = false;
|
|
151
|
+
this.adapter = undefined;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get adapter instance (for advanced usage)
|
|
155
|
+
*/
|
|
156
|
+
getAdapter() {
|
|
157
|
+
return this.adapter;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Reset error count
|
|
161
|
+
*/
|
|
162
|
+
resetErrorCount() {
|
|
163
|
+
this.errorCount = 0;
|
|
164
|
+
this.lastError = undefined;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
exports.ChatKitProvider = ChatKitProvider;
|