@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.
Files changed (46) hide show
  1. package/README.md +51 -0
  2. package/dist/adapters/openai.d.ts +106 -0
  3. package/dist/adapters/openai.js +185 -0
  4. package/dist/client.d.ts +60 -0
  5. package/dist/client.js +307 -0
  6. package/dist/errors/index.d.ts +179 -0
  7. package/dist/errors/index.js +319 -0
  8. package/dist/index.d.ts +23 -0
  9. package/dist/index.js +62 -0
  10. package/dist/live/index.d.ts +5 -0
  11. package/dist/live/index.js +10 -0
  12. package/dist/live/live-chat.d.ts +71 -0
  13. package/dist/live/live-chat.js +95 -0
  14. package/dist/live/typed-emitter.d.ts +15 -0
  15. package/dist/live/typed-emitter.js +40 -0
  16. package/dist/live/types.d.ts +24 -0
  17. package/dist/live/types.js +6 -0
  18. package/dist/modules/auth.d.ts +76 -0
  19. package/dist/modules/auth.js +59 -0
  20. package/dist/modules/chat.d.ts +164 -0
  21. package/dist/modules/chat.js +168 -0
  22. package/dist/modules/health.d.ts +45 -0
  23. package/dist/modules/health.js +22 -0
  24. package/dist/modules/knowledge.d.ts +202 -0
  25. package/dist/modules/knowledge.js +147 -0
  26. package/dist/modules/mcp.d.ts +138 -0
  27. package/dist/modules/mcp.js +110 -0
  28. package/dist/modules/prompts.d.ts +128 -0
  29. package/dist/modules/prompts.js +93 -0
  30. package/dist/modules/tools.d.ts +222 -0
  31. package/dist/modules/tools.js +302 -0
  32. package/dist/modules/toolsets.d.ts +173 -0
  33. package/dist/modules/toolsets.js +216 -0
  34. package/dist/modules/workspace.d.ts +48 -0
  35. package/dist/modules/workspace.js +49 -0
  36. package/dist/types/api.d.ts +4 -0
  37. package/dist/types/api.js +21 -0
  38. package/dist/types/config.d.ts +81 -0
  39. package/dist/types/config.js +3 -0
  40. package/dist/types/tool-calls.d.ts +60 -0
  41. package/dist/types/tool-calls.js +8 -0
  42. package/dist/types/tools.d.ts +321 -0
  43. package/dist/types/tools.js +9 -0
  44. package/dist/types/toolsets.d.ts +151 -0
  45. package/dist/types/toolsets.js +8 -0
  46. package/package.json +52 -0
@@ -0,0 +1,48 @@
1
+ import { ChanlSDK } from "../client";
2
+ import { ApiResponse } from "../types/config";
3
+ export type WorkspaceSettings = Record<string, unknown>;
4
+ export interface Workspace {
5
+ id: string;
6
+ name: string;
7
+ description?: string;
8
+ settings: WorkspaceSettings;
9
+ createdAt: string;
10
+ updatedAt: string;
11
+ }
12
+ export declare class WorkspaceModule {
13
+ private sdk;
14
+ constructor(sdk: ChanlSDK);
15
+ /**
16
+ * Create a new workspace
17
+ */
18
+ create(data: {
19
+ name: string;
20
+ description?: string;
21
+ settings?: WorkspaceSettings;
22
+ }): Promise<ApiResponse<Workspace>>;
23
+ /**
24
+ * Get workspace by ID
25
+ */
26
+ getById(id: string): Promise<ApiResponse<Workspace>>;
27
+ /**
28
+ * Get all workspaces for current user
29
+ * Uses /api/v1/auth/workspaces which returns user's accessible workspaces
30
+ */
31
+ getAll(params?: {
32
+ page?: number;
33
+ limit?: number;
34
+ }): Promise<ApiResponse<Workspace[]>>;
35
+ /**
36
+ * Update workspace
37
+ */
38
+ update(id: string, data: {
39
+ name?: string;
40
+ description?: string;
41
+ settings?: WorkspaceSettings;
42
+ }): Promise<ApiResponse<Workspace>>;
43
+ /**
44
+ * Delete workspace
45
+ */
46
+ delete(id: string): Promise<ApiResponse<void>>;
47
+ }
48
+ //# sourceMappingURL=workspace.d.ts.map
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WorkspaceModule = void 0;
4
+ class WorkspaceModule {
5
+ constructor(sdk) {
6
+ this.sdk = sdk;
7
+ }
8
+ /**
9
+ * Create a new workspace
10
+ */
11
+ async create(data) {
12
+ return this.sdk.request("POST", "/api/v1/workspaces", data);
13
+ }
14
+ /**
15
+ * Get workspace by ID
16
+ */
17
+ async getById(id) {
18
+ return this.sdk.request("GET", `/api/v1/workspaces/${id}`);
19
+ }
20
+ /**
21
+ * Get all workspaces for current user
22
+ * Uses /api/v1/auth/workspaces which returns user's accessible workspaces
23
+ */
24
+ async getAll(params) {
25
+ const queryParams = new URLSearchParams();
26
+ if (params?.page) {
27
+ queryParams.append("page", params.page.toString());
28
+ }
29
+ if (params?.limit) {
30
+ queryParams.append("limit", params.limit.toString());
31
+ }
32
+ const url = `/api/v1/auth/workspaces${queryParams.toString() ? `?${queryParams.toString()}` : ""}`;
33
+ return this.sdk.request("GET", url);
34
+ }
35
+ /**
36
+ * Update workspace
37
+ */
38
+ async update(id, data) {
39
+ return this.sdk.request("PATCH", `/api/v1/workspaces/${id}`, data);
40
+ }
41
+ /**
42
+ * Delete workspace
43
+ */
44
+ async delete(id) {
45
+ return this.sdk.request("DELETE", `/api/v1/workspaces/${id}`);
46
+ }
47
+ }
48
+ exports.WorkspaceModule = WorkspaceModule;
49
+ //# sourceMappingURL=workspace.js.map
@@ -0,0 +1,4 @@
1
+ export * from '../modules/workspace';
2
+ export * from '../modules/auth';
3
+ export * from '../modules/health';
4
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1,21 @@
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
+ // Re-export all types from modules
18
+ __exportStar(require("../modules/workspace"), exports);
19
+ __exportStar(require("../modules/auth"), exports);
20
+ __exportStar(require("../modules/health"), exports);
21
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1,81 @@
1
+ export interface ChanlConfig {
2
+ /** API base URL (e.g., 'https://api.chanl.ai' or 'http://localhost:18005') */
3
+ baseUrl: string;
4
+ /** Same as baseUrl — supported for tooling that uses `server` (e.g. local eval). */
5
+ server?: string;
6
+ /**
7
+ * When `local`, `/api/v1/...` paths are rewritten to the OSS server shape (`/scenarios`, etc.).
8
+ * When `cloud` or omitted, the platform `/api/v1` prefix is kept.
9
+ */
10
+ deployment?: 'local' | 'cloud';
11
+ /**
12
+ * Override API path prefix. Use `''` for a flat root (`/scenarios`). If set, takes precedence over `deployment`.
13
+ */
14
+ apiPrefix?: string;
15
+ /** API key for authentication */
16
+ apiKey?: string;
17
+ /** JWT token for authentication */
18
+ jwtToken?: string;
19
+ /** Auto-resolved from API key. Only needed for workspace-in-URL endpoints (audio, transcript). Set automatically — do not pass manually unless you know what you are doing. */
20
+ workspaceId?: string;
21
+ /** Request timeout in milliseconds */
22
+ timeout?: number;
23
+ /** Custom headers to include with all requests */
24
+ headers?: Record<string, string>;
25
+ /** Enable debug logging */
26
+ debug?: boolean;
27
+ /** Retry configuration */
28
+ retry?: {
29
+ maxRetries: number;
30
+ retryDelay: number;
31
+ backoffMultiplier: number;
32
+ };
33
+ }
34
+ export interface ChanlAuthConfig {
35
+ /** API key for authentication */
36
+ apiKey?: string;
37
+ /** JWT token for authentication */
38
+ jwtToken?: string;
39
+ /** User ID for user-specific operations */
40
+ userId?: string;
41
+ }
42
+ export interface RequestConfig {
43
+ /** Request timeout */
44
+ timeout?: number;
45
+ /** Custom headers */
46
+ headers?: Record<string, string>;
47
+ /** Whether to retry on failure */
48
+ retry?: boolean;
49
+ }
50
+ export interface ApiResponse<T = unknown> {
51
+ success: boolean;
52
+ data?: T;
53
+ message: string;
54
+ timestamp: string;
55
+ requestId?: string;
56
+ }
57
+ export interface PaginatedResponse<T = unknown> {
58
+ success: boolean;
59
+ data: T[];
60
+ pagination: {
61
+ page: number;
62
+ limit: number;
63
+ total: number;
64
+ totalPages: number;
65
+ hasNext: boolean;
66
+ hasPrev: boolean;
67
+ };
68
+ message: string;
69
+ timestamp: string;
70
+ }
71
+ export interface ApiError {
72
+ success: false;
73
+ error: {
74
+ code: string;
75
+ message: string;
76
+ details?: unknown;
77
+ };
78
+ timestamp: string;
79
+ requestId?: string;
80
+ }
81
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Tool Call Types for @chanl/sdk
3
+ *
4
+ * Normalized tool call data returned by Chat, Scenarios, and Calls APIs.
5
+ */
6
+ /**
7
+ * Tool call execution status
8
+ */
9
+ export type ToolCallStatus = 'success' | 'error' | 'pending' | 'timeout';
10
+ /**
11
+ * Structured error from a tool execution
12
+ */
13
+ export interface ToolCallError {
14
+ /** Error code (e.g., 'TIMEOUT', 'NETWORK_ERROR') */
15
+ code?: string;
16
+ /** Human-readable error message */
17
+ message: string;
18
+ /** Additional error details (provider-specific) */
19
+ details?: unknown;
20
+ }
21
+ /**
22
+ * Normalized tool call record
23
+ *
24
+ * Consistent format returned by Chat, Scenarios, and Call transcript APIs.
25
+ * Contains the tool name, input parameters, execution result, timing, and status.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const response = await sdk.chat.sendMessage(wsId, sessionId, 'What is the weather?');
30
+ * for (const tc of response.data.toolCalls ?? []) {
31
+ * console.log(`${tc.name}(${JSON.stringify(tc.parameters)}) → ${tc.status}`);
32
+ * if (tc.durationMs) console.log(` took ${tc.durationMs}ms`);
33
+ * }
34
+ * ```
35
+ */
36
+ export interface ToolCall {
37
+ /** Unique identifier for this tool call */
38
+ id: string;
39
+ /** Tool name (e.g., 'get_weather', 'kb_search') */
40
+ name: string;
41
+ /** Tool description (from tool definition) */
42
+ description?: string;
43
+ /** Input parameters passed to the tool */
44
+ parameters: Record<string, unknown>;
45
+ /** Tool execution result */
46
+ result?: unknown;
47
+ /** Execution status */
48
+ status: ToolCallStatus;
49
+ /** Execution duration in milliseconds */
50
+ durationMs?: number;
51
+ /** When the tool execution started (ISO timestamp) */
52
+ startedAt: string;
53
+ /** When the tool execution completed (ISO timestamp) */
54
+ completedAt?: string;
55
+ /** Seconds from call/session start (for timeline positioning) */
56
+ secondsFromStart?: number;
57
+ /** Structured error information (when status is 'error') */
58
+ error?: ToolCallError;
59
+ }
60
+ //# sourceMappingURL=tool-calls.d.ts.map
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * Tool Call Types for @chanl/sdk
4
+ *
5
+ * Normalized tool call data returned by Chat, Scenarios, and Calls APIs.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ //# sourceMappingURL=tool-calls.js.map
@@ -0,0 +1,321 @@
1
+ /**
2
+ * Tool Types for @chanl/sdk
3
+ *
4
+ * TDD Phase: RED - These types define the contract for ToolsModule
5
+ * Based on chanl-api/src/tools/ schemas and DTOs
6
+ */
7
+ export type ToolType = 'http' | 'javascript' | 'code';
8
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
9
+ export type ExecutionStatus = 'pending' | 'running' | 'completed' | 'failed' | 'corrected';
10
+ export type ExecutionSource = 'mcp' | 'api' | 'playground' | 'scheduled' | 'workflow';
11
+ /**
12
+ * HTTP tool configuration for external API calls
13
+ */
14
+ export interface HttpToolConfig {
15
+ /** HTTP method for the request */
16
+ method: HttpMethod;
17
+ /** URL template with {{variable}} placeholders */
18
+ url: string;
19
+ /** HTTP headers for the request */
20
+ headers?: Record<string, string>;
21
+ /** JSON body template with {{variable}} placeholders */
22
+ bodyTemplate?: string;
23
+ /** Request timeout in milliseconds (default: 30000) */
24
+ timeout?: number;
25
+ }
26
+ /**
27
+ * JavaScript tool configuration for sandboxed code execution
28
+ */
29
+ export interface JavaScriptToolConfig {
30
+ /** JavaScript code to execute (sandboxed) */
31
+ code: string;
32
+ /** Allowed modules for execution */
33
+ allowedModules?: string[];
34
+ }
35
+ /**
36
+ * Code execution configuration for Python/JavaScript workers
37
+ */
38
+ export interface CodeToolConfig {
39
+ /** Programming language */
40
+ language: 'python' | 'javascript';
41
+ /** Entry point function name */
42
+ entryPoint: string;
43
+ /** Cloudflare Worker name for execution */
44
+ workerName?: string;
45
+ }
46
+ /**
47
+ * Tool configuration - contains type-specific settings
48
+ */
49
+ export interface ToolConfiguration {
50
+ http?: HttpToolConfig;
51
+ javascript?: JavaScriptToolConfig;
52
+ code?: CodeToolConfig;
53
+ }
54
+ /**
55
+ * Tool execution statistics
56
+ */
57
+ export interface ToolStats {
58
+ totalCalls: number;
59
+ successfulCalls: number;
60
+ failedCalls: number;
61
+ averageLatencyMs: number;
62
+ lastCalledAt?: string;
63
+ }
64
+ /**
65
+ * Tool entity representing an MCP-compatible tool
66
+ */
67
+ export interface Tool {
68
+ /** Tool ID */
69
+ id: string;
70
+ /** Workspace ID this tool belongs to */
71
+ workspaceId: string;
72
+ /** Unique name for the tool (MCP tool name) */
73
+ name: string;
74
+ /** Description of what the tool does */
75
+ description: string;
76
+ /** Type of tool execution */
77
+ type: ToolType;
78
+ /** JSON Schema defining the tool input parameters */
79
+ inputSchema: Record<string, unknown>;
80
+ /** Tool configuration based on type */
81
+ configuration: ToolConfiguration;
82
+ /** Whether the tool is enabled */
83
+ isEnabled: boolean;
84
+ /** Tags for categorizing tools */
85
+ tags: string[];
86
+ /** User ID who created the tool */
87
+ createdBy: string;
88
+ /** User ID who last modified the tool */
89
+ lastModifiedBy?: string;
90
+ /** Execution statistics */
91
+ stats: ToolStats;
92
+ /** Creation timestamp */
93
+ createdAt: string;
94
+ /** Last update timestamp */
95
+ updatedAt: string;
96
+ }
97
+ /**
98
+ * Input for creating a new tool
99
+ */
100
+ export interface CreateToolInput {
101
+ /** Unique name for the tool (MCP tool name) */
102
+ name: string;
103
+ /** Description of what the tool does */
104
+ description: string;
105
+ /** Type of tool execution */
106
+ type: ToolType;
107
+ /** JSON Schema defining the tool input parameters */
108
+ inputSchema: Record<string, unknown>;
109
+ /** Tool configuration based on type */
110
+ configuration: ToolConfiguration;
111
+ /** Whether the tool is enabled (default: true) */
112
+ isEnabled?: boolean;
113
+ /** Tags for categorizing tools */
114
+ tags?: string[];
115
+ }
116
+ /**
117
+ * Input for updating an existing tool
118
+ */
119
+ export interface UpdateToolInput {
120
+ /** Updated name */
121
+ name?: string;
122
+ /** Updated description */
123
+ description?: string;
124
+ /** Updated type */
125
+ type?: ToolType;
126
+ /** Updated input schema */
127
+ inputSchema?: Record<string, unknown>;
128
+ /** Updated configuration */
129
+ configuration?: ToolConfiguration;
130
+ /** Updated enabled status */
131
+ isEnabled?: boolean;
132
+ /** Updated tags */
133
+ tags?: string[];
134
+ }
135
+ /**
136
+ * Filters for listing tools
137
+ */
138
+ export interface ToolFilters {
139
+ /** Filter by tool type */
140
+ type?: ToolType;
141
+ /** Filter by enabled status */
142
+ isEnabled?: boolean;
143
+ /** Search by name or description */
144
+ search?: string;
145
+ /** Filter by tag */
146
+ tag?: string;
147
+ /** Include system tools in results (default: true) */
148
+ includeSystem?: boolean;
149
+ /** Page number (1-indexed) */
150
+ page?: number;
151
+ /** Number of items per page (default: 20) */
152
+ limit?: number;
153
+ /** Sort field */
154
+ sortBy?: 'name' | 'createdAt' | 'updatedAt' | 'type';
155
+ /** Sort order */
156
+ sortOrder?: 'asc' | 'desc';
157
+ }
158
+ /**
159
+ * Correction record for input normalization
160
+ */
161
+ export interface CorrectionRecord {
162
+ field: string;
163
+ original: unknown;
164
+ corrected: unknown;
165
+ rule: string;
166
+ }
167
+ /**
168
+ * Tool execution record
169
+ */
170
+ export interface ToolExecution {
171
+ /** Execution ID */
172
+ id: string;
173
+ /** Tool ID that was executed */
174
+ toolId: string;
175
+ /** Workspace ID */
176
+ workspaceId: string;
177
+ /** User ID who triggered the execution */
178
+ userId?: string;
179
+ /** Source of the execution */
180
+ source: ExecutionSource;
181
+ /** Input arguments passed to the tool */
182
+ input: Record<string, unknown>;
183
+ /** Output from the tool execution */
184
+ output?: Record<string, unknown>;
185
+ /** Execution status */
186
+ status: ExecutionStatus;
187
+ /** Execution time in milliseconds */
188
+ executionTimeMs?: number;
189
+ /** Error message if execution failed */
190
+ errorMessage?: string;
191
+ /** Input corrections applied during normalization */
192
+ correctionsApplied?: CorrectionRecord[];
193
+ /** OpenTelemetry trace ID */
194
+ traceId?: string;
195
+ /** OpenTelemetry span ID */
196
+ spanId?: string;
197
+ /** When execution started */
198
+ startedAt?: string;
199
+ /** When execution completed */
200
+ completedAt?: string;
201
+ /** Additional metadata */
202
+ metadata?: Record<string, unknown>;
203
+ /** Creation timestamp */
204
+ createdAt: string;
205
+ /** Last update timestamp */
206
+ updatedAt: string;
207
+ }
208
+ /**
209
+ * Filters for listing executions
210
+ */
211
+ export interface ExecutionFilters {
212
+ /** Filter by execution status */
213
+ status?: ExecutionStatus;
214
+ /** Filter by execution source */
215
+ source?: ExecutionSource;
216
+ /** Filter by start date */
217
+ fromDate?: string;
218
+ /** Filter by end date */
219
+ toDate?: string;
220
+ /** Page number (1-indexed) */
221
+ page?: number;
222
+ /** Number of items per page (default: 20) */
223
+ limit?: number;
224
+ }
225
+ /**
226
+ * Response for listing tools
227
+ */
228
+ export interface ToolListResponse {
229
+ tools: Tool[];
230
+ total: number;
231
+ pagination: {
232
+ page: number;
233
+ limit: number;
234
+ totalPages: number;
235
+ hasNext: boolean;
236
+ hasPrev: boolean;
237
+ };
238
+ }
239
+ /**
240
+ * Response for single tool operations
241
+ */
242
+ export interface ToolResponse {
243
+ tool: Tool;
244
+ }
245
+ /**
246
+ * Response for tool deletion
247
+ */
248
+ export interface ToolDeleteResponse {
249
+ deleted: boolean;
250
+ }
251
+ /**
252
+ * Real-time execution result (returned by execute/test endpoints)
253
+ * Different from ToolExecution which is a stored history record
254
+ */
255
+ export interface ExecuteResult {
256
+ /** Whether the execution succeeded */
257
+ success: boolean;
258
+ /** The tool's output data */
259
+ data: unknown;
260
+ /** Execution time in milliseconds */
261
+ latencyMs: number;
262
+ /** OpenTelemetry trace ID */
263
+ traceId: string;
264
+ /** Execution record ID */
265
+ executionId: string;
266
+ /** Error message if execution failed */
267
+ error?: string;
268
+ }
269
+ /**
270
+ * Response for tool execution
271
+ * @deprecated Use ExecuteResult for real-time execution
272
+ */
273
+ export interface ToolExecutionResponse {
274
+ execution: ToolExecution;
275
+ }
276
+ /**
277
+ * Response for listing executions
278
+ */
279
+ export interface ExecutionListResponse {
280
+ data: ToolExecution[];
281
+ total: number;
282
+ page: number;
283
+ limit: number;
284
+ pagination: {
285
+ page: number;
286
+ limit: number;
287
+ totalPages: number;
288
+ hasNext: boolean;
289
+ hasPrev: boolean;
290
+ };
291
+ }
292
+ /**
293
+ * Tool category (tag) with counts
294
+ */
295
+ export interface ToolCategory {
296
+ /** Tag name */
297
+ tag: string;
298
+ /** Total count of tools with this tag */
299
+ count: number;
300
+ /** Count of enabled tools with this tag */
301
+ enabled: number;
302
+ }
303
+ /**
304
+ * Uncategorized tools count
305
+ */
306
+ export interface UncategorizedCount {
307
+ /** Total count of tools without tags */
308
+ count: number;
309
+ /** Count of enabled tools without tags */
310
+ enabled: number;
311
+ }
312
+ /**
313
+ * Response for tool categories
314
+ */
315
+ export interface ToolCategoriesResponse {
316
+ /** List of categories (tags) with counts */
317
+ categories: ToolCategory[];
318
+ /** Count of uncategorized tools */
319
+ uncategorized: UncategorizedCount;
320
+ }
321
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * Tool Types for @chanl/sdk
4
+ *
5
+ * TDD Phase: RED - These types define the contract for ToolsModule
6
+ * Based on chanl-api/src/tools/ schemas and DTOs
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ //# sourceMappingURL=tools.js.map