@protoboxai/sdk 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/README.md +51 -0
- package/dist/adapters/openai.d.ts +106 -0
- package/dist/adapters/openai.js +185 -0
- package/dist/client.d.ts +60 -0
- package/dist/client.js +307 -0
- package/dist/errors/index.d.ts +179 -0
- package/dist/errors/index.js +319 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +62 -0
- package/dist/live/index.d.ts +5 -0
- package/dist/live/index.js +10 -0
- package/dist/live/live-chat.d.ts +71 -0
- package/dist/live/live-chat.js +95 -0
- package/dist/live/typed-emitter.d.ts +15 -0
- package/dist/live/typed-emitter.js +40 -0
- package/dist/live/types.d.ts +24 -0
- package/dist/live/types.js +6 -0
- package/dist/modules/auth.d.ts +76 -0
- package/dist/modules/auth.js +59 -0
- package/dist/modules/chat.d.ts +164 -0
- package/dist/modules/chat.js +168 -0
- package/dist/modules/health.d.ts +45 -0
- package/dist/modules/health.js +22 -0
- package/dist/modules/knowledge.d.ts +202 -0
- package/dist/modules/knowledge.js +147 -0
- package/dist/modules/mcp.d.ts +138 -0
- package/dist/modules/mcp.js +110 -0
- package/dist/modules/prompts.d.ts +128 -0
- package/dist/modules/prompts.js +93 -0
- package/dist/modules/tools.d.ts +222 -0
- package/dist/modules/tools.js +302 -0
- package/dist/modules/toolsets.d.ts +173 -0
- package/dist/modules/toolsets.js +216 -0
- package/dist/modules/workspace.d.ts +48 -0
- package/dist/modules/workspace.js +49 -0
- package/dist/types/api.d.ts +4 -0
- package/dist/types/api.js +21 -0
- package/dist/types/config.d.ts +81 -0
- package/dist/types/config.js +3 -0
- package/dist/types/tool-calls.d.ts +60 -0
- package/dist/types/tool-calls.js +8 -0
- package/dist/types/tools.d.ts +321 -0
- package/dist/types/tools.js +9 -0
- package/dist/types/toolsets.d.ts +151 -0
- package/dist/types/toolsets.js +8 -0
- package/package.json +52 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Custom Error Classes for @chanl/sdk
|
|
4
|
+
*
|
|
5
|
+
* TDD Phase: RED - These errors define the error handling contract
|
|
6
|
+
*
|
|
7
|
+
* Design Principles:
|
|
8
|
+
* - Error transparency: Include code, message, and context for debugging
|
|
9
|
+
* - HTTP status awareness: Map API response codes to specific error types
|
|
10
|
+
* - Serializable details: Allow JSON serialization for logging
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.TimeoutError = exports.NetworkError = exports.ServerError = exports.RateLimitError = exports.ConflictError = exports.AuthorizationError = exports.AuthenticationError = exports.ValidationError = exports.NotFoundError = exports.ChanlError = void 0;
|
|
14
|
+
exports.isChanlError = isChanlError;
|
|
15
|
+
exports.isNotFoundError = isNotFoundError;
|
|
16
|
+
exports.isValidationError = isValidationError;
|
|
17
|
+
exports.isAuthenticationError = isAuthenticationError;
|
|
18
|
+
exports.createErrorFromResponse = createErrorFromResponse;
|
|
19
|
+
/**
|
|
20
|
+
* Base error class for all Chanl SDK errors
|
|
21
|
+
*/
|
|
22
|
+
class ChanlError extends Error {
|
|
23
|
+
constructor(message, options = {}) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = 'ChanlError';
|
|
26
|
+
this.code = options.code ?? 'CHANL_ERROR';
|
|
27
|
+
// Only assign optional properties when defined (exactOptionalPropertyTypes)
|
|
28
|
+
if (options.statusCode !== undefined) {
|
|
29
|
+
this.statusCode = options.statusCode;
|
|
30
|
+
}
|
|
31
|
+
if (options.details !== undefined) {
|
|
32
|
+
this.details = options.details;
|
|
33
|
+
}
|
|
34
|
+
if (options.cause !== undefined) {
|
|
35
|
+
this.cause = options.cause;
|
|
36
|
+
}
|
|
37
|
+
if (options.requestId !== undefined) {
|
|
38
|
+
this.requestId = options.requestId;
|
|
39
|
+
}
|
|
40
|
+
// Maintains proper stack trace in V8 environments
|
|
41
|
+
if (Error.captureStackTrace) {
|
|
42
|
+
Error.captureStackTrace(this, this.constructor);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Convert error to JSON for logging/serialization
|
|
47
|
+
*/
|
|
48
|
+
toJSON() {
|
|
49
|
+
return {
|
|
50
|
+
name: this.name,
|
|
51
|
+
code: this.code,
|
|
52
|
+
message: this.message,
|
|
53
|
+
statusCode: this.statusCode,
|
|
54
|
+
details: this.details,
|
|
55
|
+
requestId: this.requestId,
|
|
56
|
+
stack: this.stack,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.ChanlError = ChanlError;
|
|
61
|
+
/**
|
|
62
|
+
* Error thrown when a requested resource is not found (404)
|
|
63
|
+
*/
|
|
64
|
+
class NotFoundError extends ChanlError {
|
|
65
|
+
constructor(resourceType, resourceId, options = {}) {
|
|
66
|
+
const details = {
|
|
67
|
+
resourceType,
|
|
68
|
+
resourceId,
|
|
69
|
+
...options.details,
|
|
70
|
+
};
|
|
71
|
+
super(`${resourceType} with ID '${resourceId}' not found`, {
|
|
72
|
+
code: 'NOT_FOUND',
|
|
73
|
+
statusCode: 404,
|
|
74
|
+
details,
|
|
75
|
+
requestId: options.requestId,
|
|
76
|
+
});
|
|
77
|
+
this.name = 'NotFoundError';
|
|
78
|
+
this.resourceType = resourceType;
|
|
79
|
+
this.resourceId = resourceId;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.NotFoundError = NotFoundError;
|
|
83
|
+
/**
|
|
84
|
+
* Error thrown when input validation fails (400)
|
|
85
|
+
*/
|
|
86
|
+
class ValidationError extends ChanlError {
|
|
87
|
+
constructor(message, options = {}) {
|
|
88
|
+
const details = {
|
|
89
|
+
...options.details,
|
|
90
|
+
};
|
|
91
|
+
if (options.fieldErrors !== undefined) {
|
|
92
|
+
details['fieldErrors'] = options.fieldErrors;
|
|
93
|
+
}
|
|
94
|
+
super(message, {
|
|
95
|
+
code: 'VALIDATION_ERROR',
|
|
96
|
+
statusCode: 400,
|
|
97
|
+
details,
|
|
98
|
+
requestId: options.requestId,
|
|
99
|
+
});
|
|
100
|
+
this.name = 'ValidationError';
|
|
101
|
+
if (options.fieldErrors !== undefined) {
|
|
102
|
+
this.fieldErrors = options.fieldErrors;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get validation errors for a specific field
|
|
107
|
+
*/
|
|
108
|
+
getFieldErrors(field) {
|
|
109
|
+
return this.fieldErrors?.[field] ?? [];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Check if a specific field has validation errors
|
|
113
|
+
*/
|
|
114
|
+
hasFieldError(field) {
|
|
115
|
+
return (this.fieldErrors?.[field]?.length ?? 0) > 0;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.ValidationError = ValidationError;
|
|
119
|
+
/**
|
|
120
|
+
* Error thrown when authentication fails (401)
|
|
121
|
+
*/
|
|
122
|
+
class AuthenticationError extends ChanlError {
|
|
123
|
+
constructor(message = 'Authentication required', options = {}) {
|
|
124
|
+
super(message, {
|
|
125
|
+
code: 'AUTHENTICATION_ERROR',
|
|
126
|
+
statusCode: 401,
|
|
127
|
+
details: options.details,
|
|
128
|
+
requestId: options.requestId,
|
|
129
|
+
});
|
|
130
|
+
this.name = 'AuthenticationError';
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.AuthenticationError = AuthenticationError;
|
|
134
|
+
/**
|
|
135
|
+
* Error thrown when authorization fails (403)
|
|
136
|
+
*/
|
|
137
|
+
class AuthorizationError extends ChanlError {
|
|
138
|
+
constructor(message = 'Permission denied', options = {}) {
|
|
139
|
+
const details = {
|
|
140
|
+
...options.details,
|
|
141
|
+
};
|
|
142
|
+
if (options.action !== undefined) {
|
|
143
|
+
details['action'] = options.action;
|
|
144
|
+
}
|
|
145
|
+
if (options.resource !== undefined) {
|
|
146
|
+
details['resource'] = options.resource;
|
|
147
|
+
}
|
|
148
|
+
super(message, {
|
|
149
|
+
code: 'AUTHORIZATION_ERROR',
|
|
150
|
+
statusCode: 403,
|
|
151
|
+
details,
|
|
152
|
+
requestId: options.requestId,
|
|
153
|
+
});
|
|
154
|
+
this.name = 'AuthorizationError';
|
|
155
|
+
if (options.action !== undefined) {
|
|
156
|
+
this.action = options.action;
|
|
157
|
+
}
|
|
158
|
+
if (options.resource !== undefined) {
|
|
159
|
+
this.resource = options.resource;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.AuthorizationError = AuthorizationError;
|
|
164
|
+
/**
|
|
165
|
+
* Error thrown when there's a conflict (409)
|
|
166
|
+
*/
|
|
167
|
+
class ConflictError extends ChanlError {
|
|
168
|
+
constructor(message, options = {}) {
|
|
169
|
+
const details = {
|
|
170
|
+
...options.details,
|
|
171
|
+
};
|
|
172
|
+
if (options.conflictingResource !== undefined) {
|
|
173
|
+
details['conflictingResource'] = options.conflictingResource;
|
|
174
|
+
}
|
|
175
|
+
super(message, {
|
|
176
|
+
code: 'CONFLICT_ERROR',
|
|
177
|
+
statusCode: 409,
|
|
178
|
+
details,
|
|
179
|
+
requestId: options.requestId,
|
|
180
|
+
});
|
|
181
|
+
this.name = 'ConflictError';
|
|
182
|
+
if (options.conflictingResource !== undefined) {
|
|
183
|
+
this.conflictingResource = options.conflictingResource;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.ConflictError = ConflictError;
|
|
188
|
+
/**
|
|
189
|
+
* Error thrown when rate limit is exceeded (429)
|
|
190
|
+
*/
|
|
191
|
+
class RateLimitError extends ChanlError {
|
|
192
|
+
constructor(message = 'Rate limit exceeded', options = {}) {
|
|
193
|
+
const details = {
|
|
194
|
+
...options.details,
|
|
195
|
+
};
|
|
196
|
+
if (options.retryAfter !== undefined) {
|
|
197
|
+
details['retryAfter'] = options.retryAfter;
|
|
198
|
+
}
|
|
199
|
+
super(message, {
|
|
200
|
+
code: 'RATE_LIMIT_ERROR',
|
|
201
|
+
statusCode: 429,
|
|
202
|
+
details,
|
|
203
|
+
requestId: options.requestId,
|
|
204
|
+
});
|
|
205
|
+
this.name = 'RateLimitError';
|
|
206
|
+
if (options.retryAfter !== undefined) {
|
|
207
|
+
this.retryAfter = options.retryAfter;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
exports.RateLimitError = RateLimitError;
|
|
212
|
+
/**
|
|
213
|
+
* Error thrown when API server fails (5xx)
|
|
214
|
+
*/
|
|
215
|
+
class ServerError extends ChanlError {
|
|
216
|
+
constructor(message = 'Internal server error', options = {}) {
|
|
217
|
+
super(message, {
|
|
218
|
+
code: 'SERVER_ERROR',
|
|
219
|
+
statusCode: options.statusCode ?? 500,
|
|
220
|
+
details: options.details,
|
|
221
|
+
requestId: options.requestId,
|
|
222
|
+
});
|
|
223
|
+
this.name = 'ServerError';
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
exports.ServerError = ServerError;
|
|
227
|
+
/**
|
|
228
|
+
* Error thrown for network/connection issues
|
|
229
|
+
*/
|
|
230
|
+
class NetworkError extends ChanlError {
|
|
231
|
+
constructor(message = 'Network error', options = {}) {
|
|
232
|
+
super(message, {
|
|
233
|
+
code: 'NETWORK_ERROR',
|
|
234
|
+
cause: options.cause,
|
|
235
|
+
details: options.details,
|
|
236
|
+
});
|
|
237
|
+
this.name = 'NetworkError';
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
exports.NetworkError = NetworkError;
|
|
241
|
+
/**
|
|
242
|
+
* Error thrown when request times out
|
|
243
|
+
*/
|
|
244
|
+
class TimeoutError extends ChanlError {
|
|
245
|
+
constructor(message = 'Request timeout', options = {}) {
|
|
246
|
+
const details = {
|
|
247
|
+
...options.details,
|
|
248
|
+
};
|
|
249
|
+
if (options.timeoutMs !== undefined) {
|
|
250
|
+
details['timeoutMs'] = options.timeoutMs;
|
|
251
|
+
}
|
|
252
|
+
super(message, {
|
|
253
|
+
code: 'TIMEOUT_ERROR',
|
|
254
|
+
details,
|
|
255
|
+
requestId: options.requestId,
|
|
256
|
+
});
|
|
257
|
+
this.name = 'TimeoutError';
|
|
258
|
+
if (options.timeoutMs !== undefined) {
|
|
259
|
+
this.timeoutMs = options.timeoutMs;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
exports.TimeoutError = TimeoutError;
|
|
264
|
+
/**
|
|
265
|
+
* Type guard to check if error is a ChanlError
|
|
266
|
+
*/
|
|
267
|
+
function isChanlError(error) {
|
|
268
|
+
return error instanceof ChanlError;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Type guard to check if error is a NotFoundError
|
|
272
|
+
*/
|
|
273
|
+
function isNotFoundError(error) {
|
|
274
|
+
return error instanceof NotFoundError;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Type guard to check if error is a ValidationError
|
|
278
|
+
*/
|
|
279
|
+
function isValidationError(error) {
|
|
280
|
+
return error instanceof ValidationError;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Type guard to check if error is an AuthenticationError
|
|
284
|
+
*/
|
|
285
|
+
function isAuthenticationError(error) {
|
|
286
|
+
return error instanceof AuthenticationError;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Factory function to create appropriate error from API response
|
|
290
|
+
*/
|
|
291
|
+
function createErrorFromResponse(statusCode, message, options = {}) {
|
|
292
|
+
switch (statusCode) {
|
|
293
|
+
case 400:
|
|
294
|
+
return new ValidationError(message, options);
|
|
295
|
+
case 401:
|
|
296
|
+
return new AuthenticationError(message, options);
|
|
297
|
+
case 403:
|
|
298
|
+
return new AuthorizationError(message, options);
|
|
299
|
+
case 404:
|
|
300
|
+
// For 404, we need resourceType and resourceId which aren't in options
|
|
301
|
+
// Return a generic ChanlError instead
|
|
302
|
+
return new ChanlError(message, {
|
|
303
|
+
code: 'NOT_FOUND',
|
|
304
|
+
statusCode: 404,
|
|
305
|
+
details: options.details,
|
|
306
|
+
requestId: options.requestId,
|
|
307
|
+
});
|
|
308
|
+
case 409:
|
|
309
|
+
return new ConflictError(message, options);
|
|
310
|
+
case 429:
|
|
311
|
+
return new RateLimitError(message, options);
|
|
312
|
+
default:
|
|
313
|
+
if (statusCode >= 500) {
|
|
314
|
+
return new ServerError(message, { statusCode, ...options });
|
|
315
|
+
}
|
|
316
|
+
return new ChanlError(message, { statusCode, ...options });
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export { ChanlSDK, ChanlSDK as Chanl, ChanlSDK as ProtoboxSDK, ChanlSDK as Protobox } from './client';
|
|
2
|
+
export { ChanlConfig, ChanlAuthConfig } from './types/config';
|
|
3
|
+
export { WorkspaceModule } from './modules/workspace';
|
|
4
|
+
export { AuthModule } from './modules/auth';
|
|
5
|
+
export { HealthModule } from './modules/health';
|
|
6
|
+
export { PromptsModule } from './modules/prompts';
|
|
7
|
+
export { ToolsModule } from './modules/tools';
|
|
8
|
+
export { ToolsetsModule } from './modules/toolsets';
|
|
9
|
+
export { McpModule } from './modules/mcp';
|
|
10
|
+
export { KnowledgeModule } from './modules/knowledge';
|
|
11
|
+
export { ChatModule } from './modules/chat';
|
|
12
|
+
export * from './types/api';
|
|
13
|
+
export * from './modules/prompts';
|
|
14
|
+
export * from './types/tools';
|
|
15
|
+
export * from './types/tool-calls';
|
|
16
|
+
export * from './types/toolsets';
|
|
17
|
+
export * from './modules/mcp';
|
|
18
|
+
export * from './modules/knowledge';
|
|
19
|
+
export * from './modules/chat';
|
|
20
|
+
export * from './live';
|
|
21
|
+
export * from './errors';
|
|
22
|
+
export * from './adapters/openai';
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.ChatModule = exports.KnowledgeModule = exports.McpModule = exports.ToolsetsModule = exports.ToolsModule = exports.PromptsModule = exports.HealthModule = exports.AuthModule = exports.WorkspaceModule = exports.Protobox = exports.ProtoboxSDK = exports.Chanl = exports.ChanlSDK = void 0;
|
|
18
|
+
var client_1 = require("./client");
|
|
19
|
+
Object.defineProperty(exports, "ChanlSDK", { enumerable: true, get: function () { return client_1.ChanlSDK; } });
|
|
20
|
+
Object.defineProperty(exports, "Chanl", { enumerable: true, get: function () { return client_1.ChanlSDK; } });
|
|
21
|
+
Object.defineProperty(exports, "ProtoboxSDK", { enumerable: true, get: function () { return client_1.ChanlSDK; } });
|
|
22
|
+
Object.defineProperty(exports, "Protobox", { enumerable: true, get: function () { return client_1.ChanlSDK; } });
|
|
23
|
+
var workspace_1 = require("./modules/workspace");
|
|
24
|
+
Object.defineProperty(exports, "WorkspaceModule", { enumerable: true, get: function () { return workspace_1.WorkspaceModule; } });
|
|
25
|
+
var auth_1 = require("./modules/auth");
|
|
26
|
+
Object.defineProperty(exports, "AuthModule", { enumerable: true, get: function () { return auth_1.AuthModule; } });
|
|
27
|
+
var health_1 = require("./modules/health");
|
|
28
|
+
Object.defineProperty(exports, "HealthModule", { enumerable: true, get: function () { return health_1.HealthModule; } });
|
|
29
|
+
var prompts_1 = require("./modules/prompts");
|
|
30
|
+
Object.defineProperty(exports, "PromptsModule", { enumerable: true, get: function () { return prompts_1.PromptsModule; } });
|
|
31
|
+
var tools_1 = require("./modules/tools");
|
|
32
|
+
Object.defineProperty(exports, "ToolsModule", { enumerable: true, get: function () { return tools_1.ToolsModule; } });
|
|
33
|
+
var toolsets_1 = require("./modules/toolsets");
|
|
34
|
+
Object.defineProperty(exports, "ToolsetsModule", { enumerable: true, get: function () { return toolsets_1.ToolsetsModule; } });
|
|
35
|
+
var mcp_1 = require("./modules/mcp");
|
|
36
|
+
Object.defineProperty(exports, "McpModule", { enumerable: true, get: function () { return mcp_1.McpModule; } });
|
|
37
|
+
var knowledge_1 = require("./modules/knowledge");
|
|
38
|
+
Object.defineProperty(exports, "KnowledgeModule", { enumerable: true, get: function () { return knowledge_1.KnowledgeModule; } });
|
|
39
|
+
var chat_1 = require("./modules/chat");
|
|
40
|
+
Object.defineProperty(exports, "ChatModule", { enumerable: true, get: function () { return chat_1.ChatModule; } });
|
|
41
|
+
// Re-export all types from modules
|
|
42
|
+
__exportStar(require("./types/api"), exports);
|
|
43
|
+
__exportStar(require("./modules/prompts"), exports);
|
|
44
|
+
// Export tool types
|
|
45
|
+
__exportStar(require("./types/tools"), exports);
|
|
46
|
+
// Export tool call types (shared across chat)
|
|
47
|
+
__exportStar(require("./types/tool-calls"), exports);
|
|
48
|
+
// Export toolset types
|
|
49
|
+
__exportStar(require("./types/toolsets"), exports);
|
|
50
|
+
// Export MCP types
|
|
51
|
+
__exportStar(require("./modules/mcp"), exports);
|
|
52
|
+
// Export Knowledge types
|
|
53
|
+
__exportStar(require("./modules/knowledge"), exports);
|
|
54
|
+
// Export Chat types
|
|
55
|
+
__exportStar(require("./modules/chat"), exports);
|
|
56
|
+
// Export live monitoring classes
|
|
57
|
+
__exportStar(require("./live"), exports);
|
|
58
|
+
// Export error classes
|
|
59
|
+
__exportStar(require("./errors"), exports);
|
|
60
|
+
// Export OpenAI adapter
|
|
61
|
+
__exportStar(require("./adapters/openai"), exports);
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LiveChat = exports.TypedEventEmitter = void 0;
|
|
4
|
+
// Base
|
|
5
|
+
var typed_emitter_1 = require("./typed-emitter");
|
|
6
|
+
Object.defineProperty(exports, "TypedEventEmitter", { enumerable: true, get: function () { return typed_emitter_1.TypedEventEmitter; } });
|
|
7
|
+
// LiveChat
|
|
8
|
+
var live_chat_1 = require("./live-chat");
|
|
9
|
+
Object.defineProperty(exports, "LiveChat", { enumerable: true, get: function () { return live_chat_1.LiveChat; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { TypedEventEmitter } from './typed-emitter';
|
|
2
|
+
import type { ChanlSDK } from '../client';
|
|
3
|
+
import type { ChatSessionResponse, ChatMessageResponse } from '../modules/chat';
|
|
4
|
+
export type LiveChatEvents = {
|
|
5
|
+
'message': (message: ChatMessageResponse) => void;
|
|
6
|
+
'delta': (text: string) => void;
|
|
7
|
+
'ended': () => void;
|
|
8
|
+
'error': (error: Error) => void;
|
|
9
|
+
};
|
|
10
|
+
export interface LiveChatSendOptions {
|
|
11
|
+
/** Enable streaming — text arrives via `delta` events / `onChunk` callback */
|
|
12
|
+
stream?: boolean;
|
|
13
|
+
/** Per-message callback for streaming text chunks */
|
|
14
|
+
onChunk?: (delta: string) => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Live chat session wrapper.
|
|
18
|
+
*
|
|
19
|
+
* Wraps an active chat session, emitting typed events for messages and
|
|
20
|
+
* session lifecycle. Unlike LiveCall/LiveExecution, this is not polling-based —
|
|
21
|
+
* events fire in response to explicit `send()` and `end()` calls.
|
|
22
|
+
*
|
|
23
|
+
* @example Non-streaming
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const chat = await sdk.chat.session(wsId, agentId);
|
|
26
|
+
* const reply = await chat.send('Hello!');
|
|
27
|
+
* console.log(reply.message);
|
|
28
|
+
* await chat.end();
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example Streaming with event listener
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const chat = await sdk.chat.session(wsId, agentId);
|
|
34
|
+
* chat.on('delta', (text) => process.stdout.write(text));
|
|
35
|
+
* const reply = await chat.send('Hello!', { stream: true });
|
|
36
|
+
* await chat.end();
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @example Streaming with callback
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const chat = await sdk.chat.session(wsId, agentId);
|
|
42
|
+
* const reply = await chat.send('Hello!', {
|
|
43
|
+
* stream: true,
|
|
44
|
+
* onChunk: (delta) => process.stdout.write(delta),
|
|
45
|
+
* });
|
|
46
|
+
* await chat.end();
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare class LiveChat extends TypedEventEmitter<LiveChatEvents> {
|
|
50
|
+
private sdk;
|
|
51
|
+
readonly sessionId: string;
|
|
52
|
+
readonly agentName: string | undefined;
|
|
53
|
+
constructor(sdk: ChanlSDK, sessionData: ChatSessionResponse);
|
|
54
|
+
/**
|
|
55
|
+
* Send a message and receive the agent's response.
|
|
56
|
+
*
|
|
57
|
+
* With `{ stream: true }`, text arrives incrementally via the `delta`
|
|
58
|
+
* event and optional `onChunk` callback. The returned promise resolves
|
|
59
|
+
* with the complete response after the stream finishes.
|
|
60
|
+
*
|
|
61
|
+
* Without streaming (default), waits for the full response including
|
|
62
|
+
* tool calls and usage metadata.
|
|
63
|
+
*/
|
|
64
|
+
send(text: string, options?: LiveChatSendOptions): Promise<ChatMessageResponse>;
|
|
65
|
+
/**
|
|
66
|
+
* End the chat session. Emits an `ended` event.
|
|
67
|
+
*/
|
|
68
|
+
end(): Promise<void>;
|
|
69
|
+
private sendStreaming;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=live-chat.d.ts.map
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LiveChat = void 0;
|
|
4
|
+
const typed_emitter_1 = require("./typed-emitter");
|
|
5
|
+
/**
|
|
6
|
+
* Live chat session wrapper.
|
|
7
|
+
*
|
|
8
|
+
* Wraps an active chat session, emitting typed events for messages and
|
|
9
|
+
* session lifecycle. Unlike LiveCall/LiveExecution, this is not polling-based —
|
|
10
|
+
* events fire in response to explicit `send()` and `end()` calls.
|
|
11
|
+
*
|
|
12
|
+
* @example Non-streaming
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const chat = await sdk.chat.session(wsId, agentId);
|
|
15
|
+
* const reply = await chat.send('Hello!');
|
|
16
|
+
* console.log(reply.message);
|
|
17
|
+
* await chat.end();
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example Streaming with event listener
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const chat = await sdk.chat.session(wsId, agentId);
|
|
23
|
+
* chat.on('delta', (text) => process.stdout.write(text));
|
|
24
|
+
* const reply = await chat.send('Hello!', { stream: true });
|
|
25
|
+
* await chat.end();
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example Streaming with callback
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const chat = await sdk.chat.session(wsId, agentId);
|
|
31
|
+
* const reply = await chat.send('Hello!', {
|
|
32
|
+
* stream: true,
|
|
33
|
+
* onChunk: (delta) => process.stdout.write(delta),
|
|
34
|
+
* });
|
|
35
|
+
* await chat.end();
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
class LiveChat extends typed_emitter_1.TypedEventEmitter {
|
|
39
|
+
constructor(sdk, sessionData) {
|
|
40
|
+
super();
|
|
41
|
+
this.sdk = sdk;
|
|
42
|
+
this.sessionId = sessionData.interactionId || sessionData.sessionId;
|
|
43
|
+
this.agentName = sessionData.agentName;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Send a message and receive the agent's response.
|
|
47
|
+
*
|
|
48
|
+
* With `{ stream: true }`, text arrives incrementally via the `delta`
|
|
49
|
+
* event and optional `onChunk` callback. The returned promise resolves
|
|
50
|
+
* with the complete response after the stream finishes.
|
|
51
|
+
*
|
|
52
|
+
* Without streaming (default), waits for the full response including
|
|
53
|
+
* tool calls and usage metadata.
|
|
54
|
+
*/
|
|
55
|
+
async send(text, options) {
|
|
56
|
+
if (options?.stream) {
|
|
57
|
+
return this.sendStreaming(text, options);
|
|
58
|
+
}
|
|
59
|
+
const response = await this.sdk.chat.sendMessage(this.sessionId, text);
|
|
60
|
+
if (!response.success || !response.data) {
|
|
61
|
+
const error = new Error(response.message || 'Failed to send message');
|
|
62
|
+
this.emit('error', error);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
this.emit('message', response.data);
|
|
66
|
+
return response.data;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* End the chat session. Emits an `ended` event.
|
|
70
|
+
*/
|
|
71
|
+
async end() {
|
|
72
|
+
try {
|
|
73
|
+
await this.sdk.chat.endSession(this.sessionId);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Best-effort cleanup
|
|
77
|
+
}
|
|
78
|
+
this.emit('ended');
|
|
79
|
+
}
|
|
80
|
+
async sendStreaming(text, options) {
|
|
81
|
+
const response = await this.sdk.chat.streamMessage(this.sessionId, text, (delta) => {
|
|
82
|
+
this.emit('delta', delta);
|
|
83
|
+
options.onChunk?.(delta);
|
|
84
|
+
});
|
|
85
|
+
if (!response.success || !response.data) {
|
|
86
|
+
const error = new Error(response.message || 'Failed to send message');
|
|
87
|
+
this.emit('error', error);
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
this.emit('message', response.data);
|
|
91
|
+
return response.data;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.LiveChat = LiveChat;
|
|
95
|
+
//# sourceMappingURL=live-chat.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-safe EventEmitter wrapper.
|
|
3
|
+
*
|
|
4
|
+
* Uses composition (not inheritance) so `.emit()` stays protected —
|
|
5
|
+
* only subclasses can fire events, consumers can only subscribe.
|
|
6
|
+
*/
|
|
7
|
+
export declare class TypedEventEmitter<TEvents extends Record<string, (...args: any[]) => void>> {
|
|
8
|
+
private emitter;
|
|
9
|
+
on<K extends keyof TEvents & string>(event: K, listener: TEvents[K]): this;
|
|
10
|
+
once<K extends keyof TEvents & string>(event: K, listener: TEvents[K]): this;
|
|
11
|
+
off<K extends keyof TEvents & string>(event: K, listener: TEvents[K]): this;
|
|
12
|
+
protected emit<K extends keyof TEvents & string>(event: K, ...args: Parameters<TEvents[K]>): boolean;
|
|
13
|
+
removeAllListeners(): this;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=typed-emitter.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypedEventEmitter = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
/**
|
|
6
|
+
* Type-safe EventEmitter wrapper.
|
|
7
|
+
*
|
|
8
|
+
* Uses composition (not inheritance) so `.emit()` stays protected —
|
|
9
|
+
* only subclasses can fire events, consumers can only subscribe.
|
|
10
|
+
*/
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
class TypedEventEmitter {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.emitter = new events_1.EventEmitter();
|
|
15
|
+
}
|
|
16
|
+
on(event, listener) {
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
this.emitter.on(event, listener);
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
once(event, listener) {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
this.emitter.once(event, listener);
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
off(event, listener) {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
this.emitter.off(event, listener);
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
emit(event, ...args) {
|
|
32
|
+
return this.emitter.emit(event, ...args);
|
|
33
|
+
}
|
|
34
|
+
removeAllListeners() {
|
|
35
|
+
this.emitter.removeAllListeners();
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.TypedEventEmitter = TypedEventEmitter;
|
|
40
|
+
//# sourceMappingURL=typed-emitter.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for live monitoring classes
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* A single transcript segment from a call or voice scenario
|
|
6
|
+
*/
|
|
7
|
+
export interface TranscriptSegment {
|
|
8
|
+
speaker: string;
|
|
9
|
+
text: string;
|
|
10
|
+
start: number;
|
|
11
|
+
end: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Options for live monitoring (polling-based)
|
|
15
|
+
*/
|
|
16
|
+
export interface LiveOptions {
|
|
17
|
+
/** Poll interval in ms (default: 2000) */
|
|
18
|
+
pollInterval?: number;
|
|
19
|
+
/** Max polls before timeout (default: 150 = 5 min) */
|
|
20
|
+
maxPolls?: number;
|
|
21
|
+
/** External AbortSignal for cancellation */
|
|
22
|
+
signal?: AbortSignal;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=types.d.ts.map
|