@ebowwa/channel-types 0.1.1 → 0.2.1
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/dist/config.d.ts +13 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +15 -0
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/plugins/index.d.ts +4 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +5 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/registry.d.ts +100 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +150 -0
- package/dist/plugins/registry.js.map +1 -0
- package/dist/plugins/types.adapters.d.ts +126 -0
- package/dist/plugins/types.adapters.d.ts.map +1 -0
- package/dist/plugins/types.adapters.js +3 -0
- package/dist/plugins/types.adapters.js.map +1 -0
- package/dist/plugins/types.core.d.ts +82 -0
- package/dist/plugins/types.core.d.ts.map +1 -0
- package/dist/plugins/types.core.js +51 -0
- package/dist/plugins/types.core.js.map +1 -0
- package/dist/plugins/types.plugin.d.ts +141 -0
- package/dist/plugins/types.plugin.d.ts.map +1 -0
- package/dist/plugins/types.plugin.js +3 -0
- package/dist/plugins/types.plugin.js.map +1 -0
- package/package.json +13 -2
- package/src/config.js +270 -0
- package/src/config.ts +32 -1
- package/src/example.js +431 -0
- package/src/index.js +76 -0
- package/src/index.ts +5 -0
- package/src/plugins/index.ts +5 -0
- package/src/plugins/registry.ts +232 -0
- package/src/plugins/types.adapters.ts +183 -0
- package/src/plugins/types.core.ts +161 -0
- package/src/plugins/types.plugin.ts +227 -0
package/src/example.js
ADDED
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Example: Composable Channel-LLM Architecture
|
|
4
|
+
*
|
|
5
|
+
* This demonstrates how to:
|
|
6
|
+
* 1. Create a channel connector (Discord)
|
|
7
|
+
* 2. Create an LLM handler (GLM)
|
|
8
|
+
* 3. Connect them via a bridge
|
|
9
|
+
*/
|
|
10
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
11
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
12
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
13
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
14
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
15
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
16
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
20
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
21
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
22
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
23
|
+
function step(op) {
|
|
24
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
25
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
26
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
27
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
28
|
+
switch (op[0]) {
|
|
29
|
+
case 0: case 1: t = op; break;
|
|
30
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
31
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
32
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
33
|
+
default:
|
|
34
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
35
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
36
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
37
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
38
|
+
if (t[2]) _.ops.pop();
|
|
39
|
+
_.trys.pop(); continue;
|
|
40
|
+
}
|
|
41
|
+
op = body.call(thisArg, _);
|
|
42
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
43
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
47
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
48
|
+
var m = o[Symbol.asyncIterator], i;
|
|
49
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
50
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
51
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
52
|
+
};
|
|
53
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
54
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
55
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
56
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
57
|
+
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
58
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
59
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
60
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
61
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
62
|
+
function fulfill(value) { resume("next", value); }
|
|
63
|
+
function reject(value) { resume("throw", value); }
|
|
64
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
65
|
+
};
|
|
66
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
67
|
+
var index_js_1 = require("./index.js");
|
|
68
|
+
// ============================================================
|
|
69
|
+
// EXAMPLE: Discord Channel Connector
|
|
70
|
+
// ============================================================
|
|
71
|
+
var DiscordChannel = /** @class */ (function () {
|
|
72
|
+
function DiscordChannel(accountId) {
|
|
73
|
+
this.label = "Discord";
|
|
74
|
+
this.capabilities = index_js_1.RICH_CAPABILITIES;
|
|
75
|
+
this.connected = false;
|
|
76
|
+
this.id = (0, index_js_1.createChannelId)("discord", accountId);
|
|
77
|
+
}
|
|
78
|
+
DiscordChannel.prototype.start = function () {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
80
|
+
return __generator(this, function (_a) {
|
|
81
|
+
// In real impl: connect to Discord gateway
|
|
82
|
+
this.connected = true;
|
|
83
|
+
console.log("[".concat(this.label, "] Started"));
|
|
84
|
+
return [2 /*return*/];
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
DiscordChannel.prototype.stop = function () {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
90
|
+
return __generator(this, function (_a) {
|
|
91
|
+
this.connected = false;
|
|
92
|
+
console.log("[".concat(this.label, "] Stopped"));
|
|
93
|
+
return [2 /*return*/];
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
DiscordChannel.prototype.onMessage = function (handler) {
|
|
98
|
+
this.messageHandler = handler;
|
|
99
|
+
};
|
|
100
|
+
DiscordChannel.prototype.send = function (response) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
+
return __generator(this, function (_a) {
|
|
103
|
+
// In real impl: send to Discord API
|
|
104
|
+
console.log("[".concat(this.label, "] Sending: ").concat(response.content.text));
|
|
105
|
+
return [2 /*return*/];
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
DiscordChannel.prototype.stream = function (response, chunks) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
111
|
+
var fullText, chunk, e_1_1;
|
|
112
|
+
var _a, chunks_1, chunks_1_1;
|
|
113
|
+
var _b, e_1, _c, _d;
|
|
114
|
+
return __generator(this, function (_e) {
|
|
115
|
+
switch (_e.label) {
|
|
116
|
+
case 0:
|
|
117
|
+
fullText = "";
|
|
118
|
+
_e.label = 1;
|
|
119
|
+
case 1:
|
|
120
|
+
_e.trys.push([1, 6, 7, 12]);
|
|
121
|
+
_a = true, chunks_1 = __asyncValues(chunks);
|
|
122
|
+
_e.label = 2;
|
|
123
|
+
case 2: return [4 /*yield*/, chunks_1.next()];
|
|
124
|
+
case 3:
|
|
125
|
+
if (!(chunks_1_1 = _e.sent(), _b = chunks_1_1.done, !_b)) return [3 /*break*/, 5];
|
|
126
|
+
_d = chunks_1_1.value;
|
|
127
|
+
_a = false;
|
|
128
|
+
chunk = _d;
|
|
129
|
+
fullText += chunk.text;
|
|
130
|
+
console.log("[".concat(this.label, "] Stream: ").concat(fullText));
|
|
131
|
+
_e.label = 4;
|
|
132
|
+
case 4:
|
|
133
|
+
_a = true;
|
|
134
|
+
return [3 /*break*/, 2];
|
|
135
|
+
case 5: return [3 /*break*/, 12];
|
|
136
|
+
case 6:
|
|
137
|
+
e_1_1 = _e.sent();
|
|
138
|
+
e_1 = { error: e_1_1 };
|
|
139
|
+
return [3 /*break*/, 12];
|
|
140
|
+
case 7:
|
|
141
|
+
_e.trys.push([7, , 10, 11]);
|
|
142
|
+
if (!(!_a && !_b && (_c = chunks_1.return))) return [3 /*break*/, 9];
|
|
143
|
+
return [4 /*yield*/, _c.call(chunks_1)];
|
|
144
|
+
case 8:
|
|
145
|
+
_e.sent();
|
|
146
|
+
_e.label = 9;
|
|
147
|
+
case 9: return [3 /*break*/, 11];
|
|
148
|
+
case 10:
|
|
149
|
+
if (e_1) throw e_1.error;
|
|
150
|
+
return [7 /*endfinally*/];
|
|
151
|
+
case 11: return [7 /*endfinally*/];
|
|
152
|
+
case 12: return [2 /*return*/];
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
DiscordChannel.prototype.isConnected = function () {
|
|
158
|
+
return this.connected;
|
|
159
|
+
};
|
|
160
|
+
// Simulate receiving a message (for testing)
|
|
161
|
+
DiscordChannel.prototype.simulateMessage = function (text, senderId) {
|
|
162
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
163
|
+
var message, response;
|
|
164
|
+
return __generator(this, function (_a) {
|
|
165
|
+
switch (_a.label) {
|
|
166
|
+
case 0:
|
|
167
|
+
if (!this.messageHandler)
|
|
168
|
+
return [2 /*return*/];
|
|
169
|
+
message = {
|
|
170
|
+
messageId: "msg-".concat(Date.now()),
|
|
171
|
+
channelId: this.id,
|
|
172
|
+
timestamp: new Date(),
|
|
173
|
+
sender: { id: senderId, username: "user_".concat(senderId) },
|
|
174
|
+
text: text,
|
|
175
|
+
context: { isDM: true },
|
|
176
|
+
};
|
|
177
|
+
return [4 /*yield*/, this.messageHandler(message)];
|
|
178
|
+
case 1:
|
|
179
|
+
response = _a.sent();
|
|
180
|
+
if (!response) return [3 /*break*/, 3];
|
|
181
|
+
return [4 /*yield*/, this.send(response)];
|
|
182
|
+
case 2:
|
|
183
|
+
_a.sent();
|
|
184
|
+
_a.label = 3;
|
|
185
|
+
case 3: return [2 /*return*/];
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
return DiscordChannel;
|
|
191
|
+
}());
|
|
192
|
+
// ============================================================
|
|
193
|
+
// EXAMPLE: GLM LLM Handler
|
|
194
|
+
// ============================================================
|
|
195
|
+
var GLMHandler = /** @class */ (function () {
|
|
196
|
+
function GLMHandler() {
|
|
197
|
+
this.id = "glm-4.7";
|
|
198
|
+
this.model = "glm-4-flash";
|
|
199
|
+
this.ready = true;
|
|
200
|
+
}
|
|
201
|
+
GLMHandler.prototype.process = function (message) {
|
|
202
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
203
|
+
var startTime, responseText;
|
|
204
|
+
return __generator(this, function (_a) {
|
|
205
|
+
startTime = Date.now();
|
|
206
|
+
responseText = this.generateResponse(message.text);
|
|
207
|
+
return [2 /*return*/, {
|
|
208
|
+
content: {
|
|
209
|
+
text: responseText,
|
|
210
|
+
replyToOriginal: true,
|
|
211
|
+
},
|
|
212
|
+
replyTo: (0, index_js_1.createMessageRef)(message.messageId, message.channelId),
|
|
213
|
+
isComplete: true,
|
|
214
|
+
metadata: {
|
|
215
|
+
model: this.model,
|
|
216
|
+
latency: Date.now() - startTime,
|
|
217
|
+
},
|
|
218
|
+
}];
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
GLMHandler.prototype.stream = function (message) {
|
|
223
|
+
return __asyncGenerator(this, arguments, function stream_1() {
|
|
224
|
+
var response, words, i;
|
|
225
|
+
return __generator(this, function (_a) {
|
|
226
|
+
switch (_a.label) {
|
|
227
|
+
case 0: return [4 /*yield*/, __await(this.process(message))];
|
|
228
|
+
case 1:
|
|
229
|
+
response = _a.sent();
|
|
230
|
+
words = response.content.text.split(" ");
|
|
231
|
+
i = 0;
|
|
232
|
+
_a.label = 2;
|
|
233
|
+
case 2:
|
|
234
|
+
if (!(i < words.length)) return [3 /*break*/, 7];
|
|
235
|
+
return [4 /*yield*/, __await({
|
|
236
|
+
text: words[i] + " ",
|
|
237
|
+
done: i === words.length - 1,
|
|
238
|
+
seq: i,
|
|
239
|
+
})];
|
|
240
|
+
case 3: return [4 /*yield*/, _a.sent()];
|
|
241
|
+
case 4:
|
|
242
|
+
_a.sent();
|
|
243
|
+
return [4 /*yield*/, __await(new Promise(function (r) { return setTimeout(r, 50); }))];
|
|
244
|
+
case 5:
|
|
245
|
+
_a.sent();
|
|
246
|
+
_a.label = 6;
|
|
247
|
+
case 6:
|
|
248
|
+
i++;
|
|
249
|
+
return [3 /*break*/, 2];
|
|
250
|
+
case 7: return [2 /*return*/];
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
GLMHandler.prototype.isReady = function () {
|
|
256
|
+
return this.ready;
|
|
257
|
+
};
|
|
258
|
+
GLMHandler.prototype.generateResponse = function (input) {
|
|
259
|
+
// Simple echo + prefix for demo
|
|
260
|
+
if (input.toLowerCase().includes("hello")) {
|
|
261
|
+
return "Hello! How can I help you today?";
|
|
262
|
+
}
|
|
263
|
+
if (input.toLowerCase().includes("status")) {
|
|
264
|
+
return "All systems operational. GLM 4.7 is ready to assist.";
|
|
265
|
+
}
|
|
266
|
+
return "I received your message: \"".concat(input, "\"");
|
|
267
|
+
};
|
|
268
|
+
return GLMHandler;
|
|
269
|
+
}());
|
|
270
|
+
// ============================================================
|
|
271
|
+
// EXAMPLE: Simple Bridge Implementation
|
|
272
|
+
// ============================================================
|
|
273
|
+
var SimpleBridge = /** @class */ (function () {
|
|
274
|
+
function SimpleBridge() {
|
|
275
|
+
this.channels = new Map();
|
|
276
|
+
this.handlers = new Map();
|
|
277
|
+
this.defaultHandlers = new Map();
|
|
278
|
+
}
|
|
279
|
+
SimpleBridge.prototype.registerChannel = function (channel) {
|
|
280
|
+
var _this = this;
|
|
281
|
+
var key = this.channelKey(channel.id);
|
|
282
|
+
this.channels.set(key, channel);
|
|
283
|
+
// Set up message routing
|
|
284
|
+
channel.onMessage(function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
285
|
+
var handlerId, handler;
|
|
286
|
+
return __generator(this, function (_a) {
|
|
287
|
+
handlerId = this.defaultHandlers.get(key);
|
|
288
|
+
if (!handlerId) {
|
|
289
|
+
console.warn("No handler for channel ".concat(key));
|
|
290
|
+
return [2 /*return*/];
|
|
291
|
+
}
|
|
292
|
+
handler = this.handlers.get(handlerId);
|
|
293
|
+
if (!handler) {
|
|
294
|
+
console.warn("Handler ".concat(handlerId, " not found"));
|
|
295
|
+
return [2 /*return*/];
|
|
296
|
+
}
|
|
297
|
+
return [2 /*return*/, handler.process(message)];
|
|
298
|
+
});
|
|
299
|
+
}); });
|
|
300
|
+
console.log("[Bridge] Registered channel: ".concat(channel.label));
|
|
301
|
+
};
|
|
302
|
+
SimpleBridge.prototype.registerHandler = function (handler) {
|
|
303
|
+
this.handlers.set(handler.id, handler);
|
|
304
|
+
console.log("[Bridge] Registered handler: ".concat(handler.id));
|
|
305
|
+
};
|
|
306
|
+
SimpleBridge.prototype.setDefaultHandler = function (channelId, handlerId) {
|
|
307
|
+
this.defaultHandlers.set(this.channelKey(channelId), handlerId);
|
|
308
|
+
console.log("[Bridge] Set default handler: ".concat(this.channelKey(channelId), " \u2192 ").concat(handlerId));
|
|
309
|
+
};
|
|
310
|
+
SimpleBridge.prototype.start = function () {
|
|
311
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
312
|
+
var _i, _a, channel;
|
|
313
|
+
return __generator(this, function (_b) {
|
|
314
|
+
switch (_b.label) {
|
|
315
|
+
case 0:
|
|
316
|
+
_i = 0, _a = this.channels.values();
|
|
317
|
+
_b.label = 1;
|
|
318
|
+
case 1:
|
|
319
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
320
|
+
channel = _a[_i];
|
|
321
|
+
return [4 /*yield*/, channel.start()];
|
|
322
|
+
case 2:
|
|
323
|
+
_b.sent();
|
|
324
|
+
_b.label = 3;
|
|
325
|
+
case 3:
|
|
326
|
+
_i++;
|
|
327
|
+
return [3 /*break*/, 1];
|
|
328
|
+
case 4: return [2 /*return*/];
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
SimpleBridge.prototype.stop = function () {
|
|
334
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
335
|
+
var _i, _a, channel;
|
|
336
|
+
return __generator(this, function (_b) {
|
|
337
|
+
switch (_b.label) {
|
|
338
|
+
case 0:
|
|
339
|
+
_i = 0, _a = this.channels.values();
|
|
340
|
+
_b.label = 1;
|
|
341
|
+
case 1:
|
|
342
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
343
|
+
channel = _a[_i];
|
|
344
|
+
return [4 /*yield*/, channel.stop()];
|
|
345
|
+
case 2:
|
|
346
|
+
_b.sent();
|
|
347
|
+
_b.label = 3;
|
|
348
|
+
case 3:
|
|
349
|
+
_i++;
|
|
350
|
+
return [3 /*break*/, 1];
|
|
351
|
+
case 4: return [2 /*return*/];
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
};
|
|
356
|
+
SimpleBridge.prototype.getChannels = function () {
|
|
357
|
+
return Array.from(this.channels.values());
|
|
358
|
+
};
|
|
359
|
+
SimpleBridge.prototype.getHandlers = function () {
|
|
360
|
+
return Array.from(this.handlers.values());
|
|
361
|
+
};
|
|
362
|
+
SimpleBridge.prototype.channelKey = function (id) {
|
|
363
|
+
return "".concat(id.platform, ":").concat(id.accountId);
|
|
364
|
+
};
|
|
365
|
+
return SimpleBridge;
|
|
366
|
+
}());
|
|
367
|
+
// ============================================================
|
|
368
|
+
// USAGE EXAMPLE
|
|
369
|
+
// ============================================================
|
|
370
|
+
function main() {
|
|
371
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
372
|
+
var bridge, glmHandler, discordChannel;
|
|
373
|
+
return __generator(this, function (_a) {
|
|
374
|
+
switch (_a.label) {
|
|
375
|
+
case 0:
|
|
376
|
+
console.log("=== Composable Channel-LLM Example ===\n");
|
|
377
|
+
bridge = new SimpleBridge();
|
|
378
|
+
glmHandler = new GLMHandler();
|
|
379
|
+
bridge.registerHandler(glmHandler);
|
|
380
|
+
discordChannel = new DiscordChannel("my-bot-123");
|
|
381
|
+
bridge.registerChannel(discordChannel);
|
|
382
|
+
// 4. Connect channel to handler
|
|
383
|
+
bridge.setDefaultHandler(discordChannel.id, glmHandler.id);
|
|
384
|
+
// 5. Start the bridge
|
|
385
|
+
return [4 /*yield*/, bridge.start()];
|
|
386
|
+
case 1:
|
|
387
|
+
// 5. Start the bridge
|
|
388
|
+
_a.sent();
|
|
389
|
+
// 6. Simulate messages
|
|
390
|
+
console.log("\n--- Simulating messages ---\n");
|
|
391
|
+
return [4 /*yield*/, discordChannel.simulateMessage("Hello!", "user-1")];
|
|
392
|
+
case 2:
|
|
393
|
+
_a.sent();
|
|
394
|
+
return [4 /*yield*/, discordChannel.simulateMessage("What's the status?", "user-2")];
|
|
395
|
+
case 3:
|
|
396
|
+
_a.sent();
|
|
397
|
+
return [4 /*yield*/, discordChannel.simulateMessage("Can you help me with a task?", "user-3")];
|
|
398
|
+
case 4:
|
|
399
|
+
_a.sent();
|
|
400
|
+
// 7. Stop
|
|
401
|
+
console.log("\n--- Stopping ---\n");
|
|
402
|
+
return [4 /*yield*/, bridge.stop()];
|
|
403
|
+
case 5:
|
|
404
|
+
_a.sent();
|
|
405
|
+
return [2 /*return*/];
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
// Run example
|
|
411
|
+
main().catch(console.error);
|
|
412
|
+
/**
|
|
413
|
+
* Output:
|
|
414
|
+
*
|
|
415
|
+
* === Composable Channel-LLM Example ===
|
|
416
|
+
*
|
|
417
|
+
* [Bridge] Registered handler: glm-4.7
|
|
418
|
+
* [Bridge] Registered channel: Discord
|
|
419
|
+
* [Bridge] Set default handler: discord:my-bot-123 → glm-4.7
|
|
420
|
+
* [Discord] Started
|
|
421
|
+
*
|
|
422
|
+
* --- Simulating messages ---
|
|
423
|
+
*
|
|
424
|
+
* [Discord] Sending: Hello! How can I help you today?
|
|
425
|
+
* [Discord] Sending: All systems operational. GLM 4.7 is ready to assist.
|
|
426
|
+
* [Discord] Sending: I received your message: "Can you help me with a task?"
|
|
427
|
+
*
|
|
428
|
+
* --- Stopping ---
|
|
429
|
+
*
|
|
430
|
+
* [Discord] Stopped
|
|
431
|
+
*/
|
package/src/index.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @ebowwa/channel-types
|
|
4
|
+
*
|
|
5
|
+
* Composable types for channel-LLM communication.
|
|
6
|
+
*
|
|
7
|
+
* Architecture:
|
|
8
|
+
* Channel (Discord/Telegram/WhatsApp)
|
|
9
|
+
* ↓ ChannelMessage (normalized)
|
|
10
|
+
* LLMHandler.process()
|
|
11
|
+
* ↓ ChannelResponse (normalized)
|
|
12
|
+
* Channel delivers response
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.serializeChannelConfigs = exports.serializeChannelConfig = exports.parseChannelConfigs = exports.parseChannelConfig = exports.createChannelConfig = exports.getChannelsByPlatform = exports.getEnabledChannels = exports.validateChannelConfig = exports.getChannelId = exports.loadChannelConfigsFromEnv = exports.RICH_CAPABILITIES = exports.DEFAULT_CAPABILITIES = void 0;
|
|
16
|
+
exports.createChannelId = createChannelId;
|
|
17
|
+
exports.createMessageRef = createMessageRef;
|
|
18
|
+
exports.channelIdsMatch = channelIdsMatch;
|
|
19
|
+
exports.formatChannelId = formatChannelId;
|
|
20
|
+
// ============================================================
|
|
21
|
+
// UTILITY TYPES
|
|
22
|
+
// ============================================================
|
|
23
|
+
/** Create a simple channel ID */
|
|
24
|
+
function createChannelId(platform, accountId, instanceId) {
|
|
25
|
+
return { platform: platform, accountId: accountId, instanceId: instanceId };
|
|
26
|
+
}
|
|
27
|
+
/** Create a simple message ref */
|
|
28
|
+
function createMessageRef(messageId, channelId) {
|
|
29
|
+
return { messageId: messageId, channelId: channelId };
|
|
30
|
+
}
|
|
31
|
+
/** Check if two channel IDs match */
|
|
32
|
+
function channelIdsMatch(a, b) {
|
|
33
|
+
return (a.platform === b.platform &&
|
|
34
|
+
a.accountId === b.accountId &&
|
|
35
|
+
a.instanceId === b.instanceId);
|
|
36
|
+
}
|
|
37
|
+
/** Format channel ID for logging */
|
|
38
|
+
function formatChannelId(id) {
|
|
39
|
+
var base = "".concat(id.platform, ":").concat(id.accountId);
|
|
40
|
+
return id.instanceId ? "".concat(base, ":").concat(id.instanceId) : base;
|
|
41
|
+
}
|
|
42
|
+
/** Default capabilities for text-only channels */
|
|
43
|
+
exports.DEFAULT_CAPABILITIES = {
|
|
44
|
+
supports: {
|
|
45
|
+
text: true,
|
|
46
|
+
media: false,
|
|
47
|
+
replies: false,
|
|
48
|
+
threads: false,
|
|
49
|
+
reactions: false,
|
|
50
|
+
editing: false,
|
|
51
|
+
streaming: false,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
/** Full capabilities for rich channels (Discord, Slack) */
|
|
55
|
+
exports.RICH_CAPABILITIES = {
|
|
56
|
+
supports: {
|
|
57
|
+
text: true,
|
|
58
|
+
media: true,
|
|
59
|
+
replies: true,
|
|
60
|
+
threads: true,
|
|
61
|
+
reactions: true,
|
|
62
|
+
editing: true,
|
|
63
|
+
streaming: true,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
var config_js_1 = require("./config.js");
|
|
67
|
+
Object.defineProperty(exports, "loadChannelConfigsFromEnv", { enumerable: true, get: function () { return config_js_1.loadChannelConfigsFromEnv; } });
|
|
68
|
+
Object.defineProperty(exports, "getChannelId", { enumerable: true, get: function () { return config_js_1.getChannelId; } });
|
|
69
|
+
Object.defineProperty(exports, "validateChannelConfig", { enumerable: true, get: function () { return config_js_1.validateChannelConfig; } });
|
|
70
|
+
Object.defineProperty(exports, "getEnabledChannels", { enumerable: true, get: function () { return config_js_1.getEnabledChannels; } });
|
|
71
|
+
Object.defineProperty(exports, "getChannelsByPlatform", { enumerable: true, get: function () { return config_js_1.getChannelsByPlatform; } });
|
|
72
|
+
Object.defineProperty(exports, "createChannelConfig", { enumerable: true, get: function () { return config_js_1.createChannelConfig; } });
|
|
73
|
+
Object.defineProperty(exports, "parseChannelConfig", { enumerable: true, get: function () { return config_js_1.parseChannelConfig; } });
|
|
74
|
+
Object.defineProperty(exports, "parseChannelConfigs", { enumerable: true, get: function () { return config_js_1.parseChannelConfigs; } });
|
|
75
|
+
Object.defineProperty(exports, "serializeChannelConfig", { enumerable: true, get: function () { return config_js_1.serializeChannelConfig; } });
|
|
76
|
+
Object.defineProperty(exports, "serializeChannelConfigs", { enumerable: true, get: function () { return config_js_1.serializeChannelConfigs; } });
|
package/src/index.ts
CHANGED
|
@@ -25,6 +25,7 @@ export type ChannelPlatform =
|
|
|
25
25
|
| "signal"
|
|
26
26
|
| "web"
|
|
27
27
|
| "cli"
|
|
28
|
+
| "ssh"
|
|
28
29
|
| "custom";
|
|
29
30
|
|
|
30
31
|
/** Unique channel identifier */
|
|
@@ -349,6 +350,7 @@ export type {
|
|
|
349
350
|
SignalChannelConfig,
|
|
350
351
|
CLIChannelConfig,
|
|
351
352
|
WebChannelConfig,
|
|
353
|
+
SSHChannelConfig,
|
|
352
354
|
ChannelConfig,
|
|
353
355
|
ChannelConfigMap,
|
|
354
356
|
} from "./config.js";
|
|
@@ -365,3 +367,6 @@ export {
|
|
|
365
367
|
serializeChannelConfig,
|
|
366
368
|
serializeChannelConfigs,
|
|
367
369
|
} from "./config.js";
|
|
370
|
+
|
|
371
|
+
// Re-export plugin types and registry
|
|
372
|
+
export * from "./plugins/index.js";
|