@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,128 @@
1
+ import { ChanlSDK } from "../client";
2
+ import { ApiResponse } from "../types/config";
3
+ export interface PromptVariable {
4
+ name: string;
5
+ description?: string;
6
+ type: 'string' | 'number' | 'boolean' | 'array' | 'object';
7
+ required: boolean;
8
+ default?: string | number | boolean | unknown[] | Record<string, unknown>;
9
+ }
10
+ export interface Prompt {
11
+ id: string;
12
+ _id?: string;
13
+ name: string;
14
+ description?: string;
15
+ content: string;
16
+ category?: 'support' | 'sales' | 'onboarding' | 'general';
17
+ status?: 'active' | 'draft' | 'archived';
18
+ version?: number;
19
+ versionName?: string;
20
+ notes?: string;
21
+ icon?: string;
22
+ color?: string;
23
+ tags?: string[];
24
+ variables?: PromptVariable[];
25
+ usageCount?: number;
26
+ avgScore?: number;
27
+ lastModified?: string;
28
+ createdAt?: string;
29
+ updatedAt?: string;
30
+ }
31
+ export interface PromptVersion {
32
+ id: string;
33
+ _id?: string;
34
+ promptId: string;
35
+ version: string;
36
+ versionName?: string;
37
+ content: string;
38
+ variables?: PromptVariable[];
39
+ notes?: string;
40
+ isActive: boolean;
41
+ author?: string;
42
+ createdAt: string;
43
+ updatedAt?: string;
44
+ }
45
+ export interface CreatePromptData {
46
+ name: string;
47
+ description?: string;
48
+ content: string;
49
+ category?: 'support' | 'sales' | 'onboarding' | 'general';
50
+ status?: 'active' | 'draft' | 'archived';
51
+ icon?: string;
52
+ color?: string;
53
+ tags?: string[];
54
+ variables?: PromptVariable[];
55
+ notes?: string;
56
+ }
57
+ export interface UpdatePromptData {
58
+ name?: string;
59
+ description?: string;
60
+ content?: string;
61
+ category?: 'support' | 'sales' | 'onboarding' | 'general';
62
+ status?: 'active' | 'draft' | 'archived';
63
+ icon?: string;
64
+ color?: string;
65
+ tags?: string[];
66
+ variables?: PromptVariable[];
67
+ notes?: string;
68
+ versionName?: string;
69
+ }
70
+ export interface CreatePromptVersionData {
71
+ versionName?: string;
72
+ notes?: string;
73
+ content?: string;
74
+ variables?: PromptVariable[];
75
+ }
76
+ export interface PromptFilters {
77
+ search?: string;
78
+ category?: 'support' | 'sales' | 'onboarding' | 'general';
79
+ status?: 'active' | 'draft' | 'archived';
80
+ tags?: string[];
81
+ page?: number;
82
+ limit?: number;
83
+ }
84
+ export declare class PromptsModule {
85
+ private sdk;
86
+ constructor(sdk: ChanlSDK);
87
+ /**
88
+ * List all prompts with optional filters
89
+ */
90
+ list(filters?: PromptFilters): Promise<ApiResponse<Prompt[]>>;
91
+ /**
92
+ * Get a single prompt by ID
93
+ */
94
+ get(id: string): Promise<ApiResponse<Prompt>>;
95
+ /**
96
+ * Create a new prompt
97
+ */
98
+ create(data: CreatePromptData): Promise<ApiResponse<Prompt>>;
99
+ /**
100
+ * Update an existing prompt (updates current version)
101
+ */
102
+ update(id: string, data: UpdatePromptData): Promise<ApiResponse<Prompt>>;
103
+ /**
104
+ * Delete a prompt
105
+ */
106
+ delete(id: string): Promise<ApiResponse<void>>;
107
+ /**
108
+ * Get version history for a prompt
109
+ */
110
+ getVersions(promptId: string): Promise<ApiResponse<PromptVersion[]>>;
111
+ /**
112
+ * Get a specific version of a prompt
113
+ */
114
+ getVersion(promptId: string, versionId: string): Promise<ApiResponse<PromptVersion>>;
115
+ /**
116
+ * Create a new version explicitly (save as new version)
117
+ */
118
+ createVersion(promptId: string, data: CreatePromptVersionData): Promise<ApiResponse<PromptVersion>>;
119
+ /**
120
+ * Restore a version (make it the active version)
121
+ */
122
+ restoreVersion(promptId: string, versionId: string): Promise<ApiResponse<Prompt>>;
123
+ /**
124
+ * Delete a version (soft delete)
125
+ */
126
+ deleteVersion(promptId: string, versionId: string): Promise<ApiResponse<void>>;
127
+ }
128
+ //# sourceMappingURL=prompts.d.ts.map
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PromptsModule = void 0;
4
+ // ============================================================================
5
+ // PROMPTS MODULE
6
+ // ============================================================================
7
+ class PromptsModule {
8
+ constructor(sdk) {
9
+ this.sdk = sdk;
10
+ }
11
+ /**
12
+ * List all prompts with optional filters
13
+ */
14
+ async list(filters) {
15
+ const queryParams = new URLSearchParams();
16
+ if (filters?.search) {
17
+ queryParams.append("search", filters.search);
18
+ }
19
+ if (filters?.category) {
20
+ queryParams.append("category", filters.category);
21
+ }
22
+ if (filters?.status) {
23
+ queryParams.append("status", filters.status);
24
+ }
25
+ if (filters?.tags && filters.tags.length > 0) {
26
+ queryParams.append("tags", filters.tags.join(","));
27
+ }
28
+ if (filters?.page) {
29
+ queryParams.append("page", filters.page.toString());
30
+ }
31
+ if (filters?.limit) {
32
+ queryParams.append("limit", filters.limit.toString());
33
+ }
34
+ const url = `/api/v1/prompts${queryParams.toString() ? `?${queryParams.toString()}` : ""}`;
35
+ return this.sdk.request("GET", url);
36
+ }
37
+ /**
38
+ * Get a single prompt by ID
39
+ */
40
+ async get(id) {
41
+ return this.sdk.request("GET", `/api/v1/prompts/${id}`);
42
+ }
43
+ /**
44
+ * Create a new prompt
45
+ */
46
+ async create(data) {
47
+ return this.sdk.request("POST", "/api/v1/prompts", data);
48
+ }
49
+ /**
50
+ * Update an existing prompt (updates current version)
51
+ */
52
+ async update(id, data) {
53
+ return this.sdk.request("PUT", `/api/v1/prompts/${id}`, data);
54
+ }
55
+ /**
56
+ * Delete a prompt
57
+ */
58
+ async delete(id) {
59
+ return this.sdk.request("DELETE", `/api/v1/prompts/${id}`);
60
+ }
61
+ /**
62
+ * Get version history for a prompt
63
+ */
64
+ async getVersions(promptId) {
65
+ return this.sdk.request("GET", `/api/v1/prompts/${promptId}/versions`);
66
+ }
67
+ /**
68
+ * Get a specific version of a prompt
69
+ */
70
+ async getVersion(promptId, versionId) {
71
+ return this.sdk.request("GET", `/api/v1/prompts/${promptId}/versions/${versionId}`);
72
+ }
73
+ /**
74
+ * Create a new version explicitly (save as new version)
75
+ */
76
+ async createVersion(promptId, data) {
77
+ return this.sdk.request("POST", `/api/v1/prompts/${promptId}/versions`, data);
78
+ }
79
+ /**
80
+ * Restore a version (make it the active version)
81
+ */
82
+ async restoreVersion(promptId, versionId) {
83
+ return this.sdk.request("POST", `/api/v1/prompts/${promptId}/versions/${versionId}/restore`);
84
+ }
85
+ /**
86
+ * Delete a version (soft delete)
87
+ */
88
+ async deleteVersion(promptId, versionId) {
89
+ return this.sdk.request("DELETE", `/api/v1/prompts/${promptId}/versions/${versionId}`);
90
+ }
91
+ }
92
+ exports.PromptsModule = PromptsModule;
93
+ //# sourceMappingURL=prompts.js.map
@@ -0,0 +1,222 @@
1
+ /**
2
+ * ToolsModule - SDK module for MCP tool management and execution
3
+ *
4
+ * TDD Phase: GREEN - Implementation to make tests pass
5
+ *
6
+ * Provides CRUD operations for tools and execution capabilities.
7
+ * Supports both JWT auth (admin UI) and MCP API key auth.
8
+ */
9
+ import { ChanlSDK } from '../client';
10
+ import { ApiResponse } from '../types/config';
11
+ import type { Tool, ExecuteResult, CreateToolInput, UpdateToolInput, ToolFilters, ExecutionFilters, ToolListResponse, ToolDeleteResponse, ExecutionListResponse, ToolCategoriesResponse } from '../types/tools';
12
+ export declare class ToolsModule {
13
+ private sdk;
14
+ constructor(sdk: ChanlSDK);
15
+ /**
16
+ * List all tools with optional filters
17
+ *
18
+ * @param filters - Optional filters for the query
19
+ * @returns Paginated list of tools
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * // List all tools
24
+ * const { data } = await sdk.tools.list();
25
+ *
26
+ * // Filter by type and status
27
+ * const { data } = await sdk.tools.list({
28
+ * type: 'http',
29
+ * isEnabled: true,
30
+ * page: 1,
31
+ * limit: 10
32
+ * });
33
+ *
34
+ * // Exclude system tools (kb_search, chanl_reason, etc.)
35
+ * const { data } = await sdk.tools.list({
36
+ * includeSystem: false
37
+ * });
38
+ * ```
39
+ */
40
+ list(filters?: ToolFilters): Promise<ApiResponse<ToolListResponse>>;
41
+ /**
42
+ * Get a single tool by ID
43
+ *
44
+ * @param id - Tool ID
45
+ * @returns Tool details
46
+ * @throws NotFoundError if tool doesn't exist
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const { data } = await sdk.tools.get('tool_abc123');
51
+ * console.log(data.tool.name);
52
+ * ```
53
+ */
54
+ get(id: string): Promise<ApiResponse<Tool>>;
55
+ /**
56
+ * Create a new tool
57
+ *
58
+ * @param workspaceId - Workspace ID
59
+ * @param input - Tool creation data
60
+ * @returns Created tool
61
+ * @throws ValidationError if input is invalid
62
+ * @throws ConflictError if tool name already exists
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const { data } = await sdk.tools.create({
67
+ * name: 'get_weather',
68
+ * description: 'Get weather for a city',
69
+ * type: 'http',
70
+ * inputSchema: {
71
+ * type: 'object',
72
+ * properties: { city: { type: 'string' } },
73
+ * required: ['city']
74
+ * },
75
+ * configuration: {
76
+ * http: { method: 'GET', url: 'https://wttr.in/{{city}}' }
77
+ * }
78
+ * });
79
+ * ```
80
+ */
81
+ create(input: CreateToolInput): Promise<ApiResponse<Tool>>;
82
+ /**
83
+ * Update an existing tool
84
+ *
85
+ * @param workspaceId - Workspace ID
86
+ * @param id - Tool ID
87
+ * @param input - Update data
88
+ * @returns Updated tool
89
+ * @throws NotFoundError if tool doesn't exist
90
+ * @throws ValidationError if input is invalid
91
+ * @throws ConflictError if new name already exists
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * const { data } = await sdk.tools.update('tool_abc123', {
96
+ * description: 'Updated description',
97
+ * isEnabled: false
98
+ * });
99
+ * ```
100
+ */
101
+ update(id: string, input: UpdateToolInput): Promise<ApiResponse<Tool>>;
102
+ /**
103
+ * Delete a tool
104
+ *
105
+ * @param workspaceId - Workspace ID
106
+ * @param id - Tool ID
107
+ * @returns Deletion confirmation
108
+ * @throws NotFoundError if tool doesn't exist
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * const { data } = await sdk.tools.delete('tool_abc123');
113
+ * console.log(data.deleted); // true
114
+ * ```
115
+ */
116
+ delete(id: string): Promise<ApiResponse<ToolDeleteResponse>>;
117
+ /**
118
+ * Execute a tool with given arguments
119
+ *
120
+ * @param workspaceId - Workspace ID
121
+ * @param id - Tool ID
122
+ * @param args - Arguments to pass to the tool
123
+ * @returns Execution result
124
+ * @throws NotFoundError if tool doesn't exist
125
+ * @throws ValidationError if args don't match input schema
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * const { data } = await sdk.tools.execute('tool_abc123', {
130
+ * city: 'London',
131
+ * units: 'celsius'
132
+ * });
133
+ * console.log(data.output); // { temperature: 12, ... }
134
+ * ```
135
+ */
136
+ execute(id: string, args: Record<string, unknown>): Promise<ApiResponse<ExecuteResult>>;
137
+ /**
138
+ * Test a tool execution (same as execute but for testing in admin UI)
139
+ *
140
+ * @param workspaceId - Workspace ID
141
+ * @param id - Tool ID
142
+ * @param args - Arguments to pass to the tool
143
+ * @returns Execution result
144
+ * @throws NotFoundError if tool doesn't exist
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * const { data } = await sdk.tools.test('tool_abc123', {
149
+ * city: 'London'
150
+ * });
151
+ * ```
152
+ */
153
+ test(id: string, args: Record<string, unknown>): Promise<ApiResponse<ExecuteResult>>;
154
+ /**
155
+ * Get execution history for a tool
156
+ *
157
+ * @param workspaceId - Workspace ID
158
+ * @param id - Tool ID
159
+ * @param filters - Optional filters for the query
160
+ * @returns Paginated list of executions
161
+ * @throws NotFoundError if tool doesn't exist
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * // Get all executions
166
+ * const { data } = await sdk.tools.getExecutions('ws_123', 'tool_abc123');
167
+ *
168
+ * // Filter by status and date range
169
+ * const { data } = await sdk.tools.getExecutions('ws_123', 'tool_abc123', {
170
+ * status: 'completed',
171
+ * fromDate: '2025-01-01',
172
+ * toDate: '2025-01-31'
173
+ * });
174
+ * ```
175
+ */
176
+ getExecutions(id: string, filters?: ExecutionFilters): Promise<ApiResponse<ExecutionListResponse>>;
177
+ /**
178
+ * Enable a tool (shortcut for setting isEnabled=true)
179
+ *
180
+ * @param workspaceId - Workspace ID
181
+ * @param id - Tool ID
182
+ * @returns Updated tool
183
+ * @throws NotFoundError if tool doesn't exist
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * const { data } = await sdk.tools.enable('tool_abc123');
188
+ * console.log(data.tool.isEnabled); // true
189
+ * ```
190
+ */
191
+ enable(id: string): Promise<ApiResponse<Tool>>;
192
+ /**
193
+ * Disable a tool (shortcut for setting isEnabled=false)
194
+ *
195
+ * @param workspaceId - Workspace ID
196
+ * @param id - Tool ID
197
+ * @returns Updated tool
198
+ * @throws NotFoundError if tool doesn't exist
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * const { data } = await sdk.tools.disable('tool_abc123');
203
+ * console.log(data.tool.isEnabled); // false
204
+ * ```
205
+ */
206
+ disable(id: string): Promise<ApiResponse<Tool>>;
207
+ /**
208
+ * Get tool categories (aggregated tags with counts)
209
+ *
210
+ * @param workspaceId - Workspace ID
211
+ * @returns List of categories with counts
212
+ *
213
+ * @example
214
+ * ```typescript
215
+ * const { data } = await sdk.tools.getCategories('ws_123');
216
+ * console.log(data.categories);
217
+ * // [{ name: 'weather', count: 5, enabledCount: 3 }, ...]
218
+ * ```
219
+ */
220
+ getCategories(): Promise<ApiResponse<ToolCategoriesResponse>>;
221
+ }
222
+ //# sourceMappingURL=tools.d.ts.map