@chanl-ai/sdk 2.0.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.
Files changed (137) hide show
  1. package/dist/adapters/openai.d.ts +106 -0
  2. package/dist/adapters/openai.d.ts.map +1 -0
  3. package/dist/adapters/openai.js +185 -0
  4. package/dist/adapters/openai.js.map +1 -0
  5. package/dist/client.d.ts +74 -0
  6. package/dist/client.d.ts.map +1 -0
  7. package/dist/client.js +293 -0
  8. package/dist/client.js.map +1 -0
  9. package/dist/errors/index.d.ts +179 -0
  10. package/dist/errors/index.d.ts.map +1 -0
  11. package/dist/errors/index.js +319 -0
  12. package/dist/errors/index.js.map +1 -0
  13. package/dist/index.d.ts +38 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +76 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/live/index.d.ts +9 -0
  18. package/dist/live/index.d.ts.map +1 -0
  19. package/dist/live/index.js +16 -0
  20. package/dist/live/index.js.map +1 -0
  21. package/dist/live/live-call.d.ts +48 -0
  22. package/dist/live/live-call.d.ts.map +1 -0
  23. package/dist/live/live-call.js +148 -0
  24. package/dist/live/live-call.js.map +1 -0
  25. package/dist/live/live-chat.d.ts +71 -0
  26. package/dist/live/live-chat.d.ts.map +1 -0
  27. package/dist/live/live-chat.js +95 -0
  28. package/dist/live/live-chat.js.map +1 -0
  29. package/dist/live/live-execution.d.ts +55 -0
  30. package/dist/live/live-execution.d.ts.map +1 -0
  31. package/dist/live/live-execution.js +170 -0
  32. package/dist/live/live-execution.js.map +1 -0
  33. package/dist/live/typed-emitter.d.ts +15 -0
  34. package/dist/live/typed-emitter.d.ts.map +1 -0
  35. package/dist/live/typed-emitter.js +40 -0
  36. package/dist/live/typed-emitter.js.map +1 -0
  37. package/dist/live/types.d.ts +24 -0
  38. package/dist/live/types.d.ts.map +1 -0
  39. package/dist/live/types.js +6 -0
  40. package/dist/live/types.js.map +1 -0
  41. package/dist/modules/agents.d.ts +378 -0
  42. package/dist/modules/agents.d.ts.map +1 -0
  43. package/dist/modules/agents.js +259 -0
  44. package/dist/modules/agents.js.map +1 -0
  45. package/dist/modules/alerts.d.ts +43 -0
  46. package/dist/modules/alerts.d.ts.map +1 -0
  47. package/dist/modules/alerts.js +56 -0
  48. package/dist/modules/alerts.js.map +1 -0
  49. package/dist/modules/audio.d.ts +47 -0
  50. package/dist/modules/audio.d.ts.map +1 -0
  51. package/dist/modules/audio.js +75 -0
  52. package/dist/modules/audio.js.map +1 -0
  53. package/dist/modules/auth.d.ts +76 -0
  54. package/dist/modules/auth.d.ts.map +1 -0
  55. package/dist/modules/auth.js +59 -0
  56. package/dist/modules/auth.js.map +1 -0
  57. package/dist/modules/calls.d.ts +825 -0
  58. package/dist/modules/calls.d.ts.map +1 -0
  59. package/dist/modules/calls.js +398 -0
  60. package/dist/modules/calls.js.map +1 -0
  61. package/dist/modules/chat.d.ts +165 -0
  62. package/dist/modules/chat.d.ts.map +1 -0
  63. package/dist/modules/chat.js +169 -0
  64. package/dist/modules/chat.js.map +1 -0
  65. package/dist/modules/health.d.ts +45 -0
  66. package/dist/modules/health.d.ts.map +1 -0
  67. package/dist/modules/health.js +22 -0
  68. package/dist/modules/health.js.map +1 -0
  69. package/dist/modules/knowledge.d.ts +202 -0
  70. package/dist/modules/knowledge.d.ts.map +1 -0
  71. package/dist/modules/knowledge.js +147 -0
  72. package/dist/modules/knowledge.js.map +1 -0
  73. package/dist/modules/mcp.d.ts +140 -0
  74. package/dist/modules/mcp.d.ts.map +1 -0
  75. package/dist/modules/mcp.js +110 -0
  76. package/dist/modules/mcp.js.map +1 -0
  77. package/dist/modules/memory.d.ts +163 -0
  78. package/dist/modules/memory.d.ts.map +1 -0
  79. package/dist/modules/memory.js +208 -0
  80. package/dist/modules/memory.js.map +1 -0
  81. package/dist/modules/personas.d.ts +168 -0
  82. package/dist/modules/personas.d.ts.map +1 -0
  83. package/dist/modules/personas.js +106 -0
  84. package/dist/modules/personas.js.map +1 -0
  85. package/dist/modules/prompts.d.ts +128 -0
  86. package/dist/modules/prompts.d.ts.map +1 -0
  87. package/dist/modules/prompts.js +93 -0
  88. package/dist/modules/prompts.js.map +1 -0
  89. package/dist/modules/scenarios.d.ts +294 -0
  90. package/dist/modules/scenarios.d.ts.map +1 -0
  91. package/dist/modules/scenarios.js +349 -0
  92. package/dist/modules/scenarios.js.map +1 -0
  93. package/dist/modules/scorecard.d.ts +642 -0
  94. package/dist/modules/scorecard.d.ts.map +1 -0
  95. package/dist/modules/scorecard.js +327 -0
  96. package/dist/modules/scorecard.js.map +1 -0
  97. package/dist/modules/tools.d.ts +222 -0
  98. package/dist/modules/tools.d.ts.map +1 -0
  99. package/dist/modules/tools.js +302 -0
  100. package/dist/modules/tools.js.map +1 -0
  101. package/dist/modules/toolsets.d.ts +173 -0
  102. package/dist/modules/toolsets.d.ts.map +1 -0
  103. package/dist/modules/toolsets.js +216 -0
  104. package/dist/modules/toolsets.js.map +1 -0
  105. package/dist/modules/transcript.d.ts +60 -0
  106. package/dist/modules/transcript.d.ts.map +1 -0
  107. package/dist/modules/transcript.js +69 -0
  108. package/dist/modules/transcript.js.map +1 -0
  109. package/dist/modules/workspace.d.ts +48 -0
  110. package/dist/modules/workspace.d.ts.map +1 -0
  111. package/dist/modules/workspace.js +49 -0
  112. package/dist/modules/workspace.js.map +1 -0
  113. package/dist/types/api.d.ts +8 -0
  114. package/dist/types/api.d.ts.map +1 -0
  115. package/dist/types/api.js +25 -0
  116. package/dist/types/api.js.map +1 -0
  117. package/dist/types/config.d.ts +70 -0
  118. package/dist/types/config.d.ts.map +1 -0
  119. package/dist/types/config.js +3 -0
  120. package/dist/types/config.js.map +1 -0
  121. package/dist/types/memory.d.ts +243 -0
  122. package/dist/types/memory.d.ts.map +1 -0
  123. package/dist/types/memory.js +9 -0
  124. package/dist/types/memory.js.map +1 -0
  125. package/dist/types/tool-calls.d.ts +61 -0
  126. package/dist/types/tool-calls.d.ts.map +1 -0
  127. package/dist/types/tool-calls.js +9 -0
  128. package/dist/types/tool-calls.js.map +1 -0
  129. package/dist/types/tools.d.ts +321 -0
  130. package/dist/types/tools.d.ts.map +1 -0
  131. package/dist/types/tools.js +9 -0
  132. package/dist/types/tools.js.map +1 -0
  133. package/dist/types/toolsets.d.ts +149 -0
  134. package/dist/types/toolsets.d.ts.map +1 -0
  135. package/dist/types/toolsets.js +8 -0
  136. package/dist/types/toolsets.js.map +1 -0
  137. package/package.json +60 -0
@@ -0,0 +1,106 @@
1
+ /**
2
+ * OpenAI Adapter for @chanl-ai/sdk
3
+ *
4
+ * TDD Phase: GREEN - Implementation to make tests pass
5
+ *
6
+ * Provides integration with OpenAI's function calling format:
7
+ * 1. Convert Chanl tools to OpenAI ChatCompletionTool format
8
+ * 2. Execute tool calls from OpenAI responses
9
+ */
10
+ import { ChanlSDK } from '../client';
11
+ /**
12
+ * OpenAI function definition
13
+ */
14
+ export interface OpenAIFunction {
15
+ name: string;
16
+ description: string;
17
+ parameters: Record<string, unknown>;
18
+ }
19
+ /**
20
+ * OpenAI ChatCompletionTool format
21
+ */
22
+ export interface OpenAIChatCompletionTool {
23
+ type: 'function';
24
+ function: OpenAIFunction;
25
+ }
26
+ /**
27
+ * OpenAI tool call from assistant response
28
+ */
29
+ export interface OpenAIToolCall {
30
+ id: string;
31
+ type: 'function';
32
+ function: {
33
+ name: string;
34
+ arguments: string;
35
+ };
36
+ }
37
+ /**
38
+ * Tool output for OpenAI messages
39
+ * Matches OpenAI's ChatCompletionToolMessageParam
40
+ */
41
+ export interface ToolOutput {
42
+ tool_call_id: string;
43
+ role: 'tool';
44
+ content: string;
45
+ }
46
+ /**
47
+ * Options for fetching tools
48
+ */
49
+ export interface GetToolsOptions {
50
+ /** Filter by tag */
51
+ tag?: string;
52
+ }
53
+ /**
54
+ * Adapter to integrate Chanl tools with OpenAI's function calling
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * const adapter = new OpenAIAdapter(sdk, 'ws_abc123');
59
+ *
60
+ * // Get tools as OpenAI functions
61
+ * const tools = await adapter.getToolsAsOpenAIFunctions();
62
+ *
63
+ * // Use with OpenAI
64
+ * const response = await openai.chat.completions.create({
65
+ * model: 'gpt-4',
66
+ * messages: [...],
67
+ * tools,
68
+ * });
69
+ *
70
+ * // Execute tool calls from response
71
+ * if (response.choices[0].message.tool_calls) {
72
+ * const results = await adapter.executeToolCalls(
73
+ * response.choices[0].message.tool_calls
74
+ * );
75
+ * }
76
+ * ```
77
+ */
78
+ export declare class OpenAIAdapter {
79
+ private sdk;
80
+ /** Cached tools for lookup during execution */
81
+ private toolsCache;
82
+ constructor(sdk: ChanlSDK);
83
+ /**
84
+ * Convert Chanl tools to OpenAI function calling format
85
+ *
86
+ * @param options - Optional filters for which tools to include
87
+ * @returns Array of OpenAI ChatCompletionTool objects
88
+ */
89
+ getToolsAsOpenAIFunctions(options?: GetToolsOptions): Promise<OpenAIChatCompletionTool[]>;
90
+ /**
91
+ * Execute tool calls from an OpenAI response
92
+ *
93
+ * @param toolCalls - Array of tool calls from OpenAI assistant message
94
+ * @returns Array of tool outputs ready for OpenAI messages
95
+ */
96
+ executeToolCalls(toolCalls: OpenAIToolCall[]): Promise<ToolOutput[]>;
97
+ /**
98
+ * Convert a single Chanl tool to OpenAI function format
99
+ */
100
+ private convertToolToOpenAI;
101
+ /**
102
+ * Execute a single tool call
103
+ */
104
+ private executeSingleToolCall;
105
+ }
106
+ //# sourceMappingURL=openai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/adapters/openai.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAOrC;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,cAAc,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAMD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,oBAAoB;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,aAAa;IAKtB,OAAO,CAAC,GAAG;IAJb,+CAA+C;IAC/C,OAAO,CAAC,UAAU,CAAgC;gBAGxC,GAAG,EAAE,QAAQ;IAGvB;;;;;OAKG;IACG,yBAAyB,CAC7B,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,wBAAwB,EAAE,CAAC;IAwBtC;;;;;OAKG;IACG,gBAAgB,CAAC,SAAS,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAoB1E;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAW3B;;OAEG;YACW,qBAAqB;CAuFpC"}
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ /**
3
+ * OpenAI Adapter for @chanl-ai/sdk
4
+ *
5
+ * TDD Phase: GREEN - Implementation to make tests pass
6
+ *
7
+ * Provides integration with OpenAI's function calling format:
8
+ * 1. Convert Chanl tools to OpenAI ChatCompletionTool format
9
+ * 2. Execute tool calls from OpenAI responses
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OpenAIAdapter = void 0;
13
+ /**
14
+ * Adapter to integrate Chanl tools with OpenAI's function calling
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const adapter = new OpenAIAdapter(sdk, 'ws_abc123');
19
+ *
20
+ * // Get tools as OpenAI functions
21
+ * const tools = await adapter.getToolsAsOpenAIFunctions();
22
+ *
23
+ * // Use with OpenAI
24
+ * const response = await openai.chat.completions.create({
25
+ * model: 'gpt-4',
26
+ * messages: [...],
27
+ * tools,
28
+ * });
29
+ *
30
+ * // Execute tool calls from response
31
+ * if (response.choices[0].message.tool_calls) {
32
+ * const results = await adapter.executeToolCalls(
33
+ * response.choices[0].message.tool_calls
34
+ * );
35
+ * }
36
+ * ```
37
+ */
38
+ class OpenAIAdapter {
39
+ constructor(sdk) {
40
+ this.sdk = sdk;
41
+ /** Cached tools for lookup during execution */
42
+ this.toolsCache = new Map();
43
+ }
44
+ /**
45
+ * Convert Chanl tools to OpenAI function calling format
46
+ *
47
+ * @param options - Optional filters for which tools to include
48
+ * @returns Array of OpenAI ChatCompletionTool objects
49
+ */
50
+ async getToolsAsOpenAIFunctions(options = {}) {
51
+ const filters = {
52
+ isEnabled: true,
53
+ };
54
+ if (options.tag) {
55
+ filters.tag = options.tag;
56
+ }
57
+ const response = await this.sdk.tools.list(filters);
58
+ if (!response.success || !response.data?.tools) {
59
+ return [];
60
+ }
61
+ // Cache tools for later execution
62
+ this.toolsCache.clear();
63
+ for (const tool of response.data.tools) {
64
+ this.toolsCache.set(tool.name, tool);
65
+ }
66
+ return response.data.tools.map((tool) => this.convertToolToOpenAI(tool));
67
+ }
68
+ /**
69
+ * Execute tool calls from an OpenAI response
70
+ *
71
+ * @param toolCalls - Array of tool calls from OpenAI assistant message
72
+ * @returns Array of tool outputs ready for OpenAI messages
73
+ */
74
+ async executeToolCalls(toolCalls) {
75
+ if (toolCalls.length === 0) {
76
+ return [];
77
+ }
78
+ // Refresh cache if empty
79
+ if (this.toolsCache.size === 0) {
80
+ await this.getToolsAsOpenAIFunctions();
81
+ }
82
+ const results = [];
83
+ for (const toolCall of toolCalls) {
84
+ const result = await this.executeSingleToolCall(toolCall);
85
+ results.push(result);
86
+ }
87
+ return results;
88
+ }
89
+ /**
90
+ * Convert a single Chanl tool to OpenAI function format
91
+ */
92
+ convertToolToOpenAI(tool) {
93
+ return {
94
+ type: 'function',
95
+ function: {
96
+ name: tool.name,
97
+ description: tool.description,
98
+ parameters: tool.inputSchema,
99
+ },
100
+ };
101
+ }
102
+ /**
103
+ * Execute a single tool call
104
+ */
105
+ async executeSingleToolCall(toolCall) {
106
+ const { id, function: func } = toolCall;
107
+ const { name, arguments: argsString } = func;
108
+ // Find the tool
109
+ const tool = this.toolsCache.get(name);
110
+ if (!tool) {
111
+ return {
112
+ tool_call_id: id,
113
+ role: 'tool',
114
+ content: JSON.stringify({
115
+ error: `Tool '${name}' not found`,
116
+ }),
117
+ };
118
+ }
119
+ // Parse arguments
120
+ let args;
121
+ try {
122
+ args = JSON.parse(argsString);
123
+ }
124
+ catch {
125
+ return {
126
+ tool_call_id: id,
127
+ role: 'tool',
128
+ content: JSON.stringify({
129
+ error: `Invalid JSON arguments: ${argsString}`,
130
+ }),
131
+ };
132
+ }
133
+ // Execute the tool
134
+ try {
135
+ const response = await this.sdk.tools.execute(tool.id, args);
136
+ if (!response.success) {
137
+ return {
138
+ tool_call_id: id,
139
+ role: 'tool',
140
+ content: JSON.stringify({
141
+ error: response.message ?? 'Tool execution failed',
142
+ }),
143
+ };
144
+ }
145
+ const execution = response.data;
146
+ // Handle undefined execution data
147
+ if (!execution) {
148
+ return {
149
+ tool_call_id: id,
150
+ role: 'tool',
151
+ content: JSON.stringify({
152
+ error: 'No execution data returned',
153
+ }),
154
+ };
155
+ }
156
+ // Check if execution failed
157
+ if (!execution.success) {
158
+ return {
159
+ tool_call_id: id,
160
+ role: 'tool',
161
+ content: JSON.stringify({
162
+ error: execution.error ?? 'Execution failed',
163
+ }),
164
+ };
165
+ }
166
+ // Return successful output
167
+ return {
168
+ tool_call_id: id,
169
+ role: 'tool',
170
+ content: JSON.stringify(execution.data ?? {}),
171
+ };
172
+ }
173
+ catch (error) {
174
+ return {
175
+ tool_call_id: id,
176
+ role: 'tool',
177
+ content: JSON.stringify({
178
+ error: error instanceof Error ? error.message : 'Unknown execution error',
179
+ }),
180
+ };
181
+ }
182
+ }
183
+ }
184
+ exports.OpenAIAdapter = OpenAIAdapter;
185
+ //# sourceMappingURL=openai.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/adapters/openai.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AA4DH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAa,aAAa;IAIxB,YACU,GAAa;QAAb,QAAG,GAAH,GAAG,CAAU;QAJvB,+CAA+C;QACvC,eAAU,GAAsB,IAAI,GAAG,EAAE,CAAC;IAI/C,CAAC;IAEJ;;;;;OAKG;IACH,KAAK,CAAC,yBAAyB,CAC7B,UAA2B,EAAE;QAE7B,MAAM,OAAO,GAAgB;YAC3B,SAAS,EAAE,IAAI;SAChB,CAAC;QAEF,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;YAChB,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;QAC5B,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAEpD,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;YAC/C,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,kCAAkC;QAClC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxB,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YACvC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CA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AI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;gBACvB,OAAO;oBACL,YAAY,EAAE,EAAE;oBAChB,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC;wBACtB,KAAK,EAAE,SAAS,CAAC,KAAK,IAAI,kBAAkB;qBAC7C,CAAC;iBACH,CAAC;YACJ,CAAC;YAED,2BAA2B;YAC3B,OAAO;gBACL,YAAY,EAAE,EAAE;gBAChB,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,IAAI,EAAE,CAAC;aAC9C,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,YAAY,EAAE,EAAE;gBAChB,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC;oBACtB,KAAK,EACH,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,yBAAyB;iBACrE,CAAC;aACH,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AA1KD,sCA0KC"}
@@ -0,0 +1,74 @@
1
+ import { ChanlConfig, RequestConfig, ApiResponse } from "./types/config";
2
+ import { AudioModule } from "./modules/audio";
3
+ import { TranscriptModule } from "./modules/transcript";
4
+ import { ScorecardModule } from "./modules/scorecard";
5
+ import { WorkspaceModule } from "./modules/workspace";
6
+ import { AlertModule } from "./modules/alerts";
7
+ import { AuthModule } from "./modules/auth";
8
+ import { HealthModule } from "./modules/health";
9
+ import { PromptsModule } from "./modules/prompts";
10
+ import { ToolsModule } from "./modules/tools";
11
+ import { ToolsetsModule } from "./modules/toolsets";
12
+ import { ScenariosModule } from "./modules/scenarios";
13
+ import { AgentsModule } from "./modules/agents";
14
+ import { PersonasModule } from "./modules/personas";
15
+ import { CallsModule } from "./modules/calls";
16
+ import { McpModule } from "./modules/mcp";
17
+ import { KnowledgeModule } from "./modules/knowledge";
18
+ import { MemoryModule } from "./modules/memory";
19
+ import { ChatModule } from "./modules/chat";
20
+ export declare class ChanlSDK {
21
+ private config;
22
+ readonly audio: AudioModule;
23
+ readonly transcript: TranscriptModule;
24
+ readonly scorecard: ScorecardModule;
25
+ readonly workspace: WorkspaceModule;
26
+ readonly alerts: AlertModule;
27
+ readonly auth: AuthModule;
28
+ readonly health: HealthModule;
29
+ readonly prompts: PromptsModule;
30
+ readonly tools: ToolsModule;
31
+ readonly toolsets: ToolsetsModule;
32
+ readonly scenarios: ScenariosModule;
33
+ readonly agents: AgentsModule;
34
+ readonly personas: PersonasModule;
35
+ readonly calls: CallsModule;
36
+ readonly mcp: McpModule;
37
+ readonly knowledge: KnowledgeModule;
38
+ readonly memory: MemoryModule;
39
+ readonly chat: ChatModule;
40
+ constructor(config: ChanlConfig);
41
+ /**
42
+ * Make a request to the API
43
+ */
44
+ request<T = unknown>(method: string, url: string, data?: unknown, config?: RequestConfig): Promise<ApiResponse<T>>;
45
+ /**
46
+ * Make a streaming request that returns the raw Response.
47
+ *
48
+ * Unlike `request()`, this does NOT parse JSON or apply timeout.
49
+ * The caller reads `response.body` via `getReader()`.
50
+ * Used for SSE / chunked-transfer endpoints (e.g., chat streaming).
51
+ */
52
+ requestStream(method: string, url: string, data?: unknown): Promise<Response>;
53
+ /**
54
+ * Recursively normalize _id → id in response data.
55
+ * Skips if id already exists to avoid overwriting.
56
+ */
57
+ private normalizeIds;
58
+ /**
59
+ * Update authentication credentials
60
+ */
61
+ updateAuth(authConfig: {
62
+ apiKey?: string;
63
+ jwtToken?: string;
64
+ }): void;
65
+ /**
66
+ * Get current configuration
67
+ */
68
+ getConfig(): ChanlConfig;
69
+ /**
70
+ * Enable/disable debug logging
71
+ */
72
+ setDebug(enabled: boolean): void;
73
+ }
74
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,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ChanlSDK = void 0;
4
+ const audio_1 = require("./modules/audio");
5
+ const transcript_1 = require("./modules/transcript");
6
+ const scorecard_1 = require("./modules/scorecard");
7
+ const workspace_1 = require("./modules/workspace");
8
+ const alerts_1 = require("./modules/alerts");
9
+ const auth_1 = require("./modules/auth");
10
+ const health_1 = require("./modules/health");
11
+ const prompts_1 = require("./modules/prompts");
12
+ const tools_1 = require("./modules/tools");
13
+ const toolsets_1 = require("./modules/toolsets");
14
+ const scenarios_1 = require("./modules/scenarios");
15
+ const agents_1 = require("./modules/agents");
16
+ const personas_1 = require("./modules/personas");
17
+ const calls_1 = require("./modules/calls");
18
+ const mcp_1 = require("./modules/mcp");
19
+ const knowledge_1 = require("./modules/knowledge");
20
+ const memory_1 = require("./modules/memory");
21
+ const chat_1 = require("./modules/chat");
22
+ class ChanlSDK {
23
+ constructor(config) {
24
+ this.config = {
25
+ timeout: 30000,
26
+ debug: false,
27
+ retry: {
28
+ maxRetries: 3,
29
+ retryDelay: 1000,
30
+ backoffMultiplier: 2,
31
+ },
32
+ ...config,
33
+ };
34
+ // Initialize modules
35
+ this.audio = new audio_1.AudioModule(this);
36
+ this.transcript = new transcript_1.TranscriptModule(this);
37
+ this.scorecard = new scorecard_1.ScorecardModule(this);
38
+ this.workspace = new workspace_1.WorkspaceModule(this);
39
+ this.alerts = new alerts_1.AlertModule(this);
40
+ this.auth = new auth_1.AuthModule(this);
41
+ this.health = new health_1.HealthModule(this);
42
+ this.prompts = new prompts_1.PromptsModule(this);
43
+ this.tools = new tools_1.ToolsModule(this);
44
+ this.toolsets = new toolsets_1.ToolsetsModule(this);
45
+ this.scenarios = new scenarios_1.ScenariosModule(this);
46
+ this.agents = new agents_1.AgentsModule(this);
47
+ this.personas = new personas_1.PersonasModule(this);
48
+ this.calls = new calls_1.CallsModule(this);
49
+ this.mcp = new mcp_1.McpModule(this);
50
+ this.knowledge = new knowledge_1.KnowledgeModule(this);
51
+ this.memory = new memory_1.MemoryModule(this);
52
+ this.chat = new chat_1.ChatModule(this);
53
+ }
54
+ /**
55
+ * Make a request to the API
56
+ */
57
+ async request(method, url, data, config) {
58
+ // Check if data is FormData (Node.js form-data package or native FormData)
59
+ const isNodeFormData = data != null &&
60
+ typeof data
61
+ .getHeaders === "function";
62
+ const isNativeFormData = typeof FormData !== "undefined" && data instanceof FormData;
63
+ const isFormData = isNodeFormData || isNativeFormData;
64
+ // Build full URL
65
+ const fullUrl = new URL(url, this.config.baseUrl).toString();
66
+ // Build headers
67
+ const headers = {
68
+ ...this.config.headers,
69
+ ...config?.headers,
70
+ };
71
+ // Set Content-Type for non-FormData requests (FormData sets its own boundary)
72
+ if (!isFormData && !headers["Content-Type"]) {
73
+ headers["Content-Type"] = "application/json";
74
+ }
75
+ // Remove Content-Type for FormData to let fetch/runtime set it with boundary
76
+ if (isFormData) {
77
+ delete headers["Content-Type"];
78
+ }
79
+ // Add authentication
80
+ if (this.config.apiKey) {
81
+ headers["X-API-Key"] = this.config.apiKey;
82
+ }
83
+ else if (this.config.jwtToken) {
84
+ headers["Authorization"] = `Bearer ${this.config.jwtToken}`;
85
+ }
86
+ // Add workspace context
87
+ if (this.config.workspaceId) {
88
+ headers["x-workspace-id"] = this.config.workspaceId;
89
+ }
90
+ // Setup timeout via AbortController
91
+ const timeout = config?.timeout ?? this.config.timeout ?? 30000;
92
+ const controller = new AbortController();
93
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
94
+ // Build fetch options
95
+ const fetchOptions = {
96
+ method,
97
+ headers,
98
+ signal: controller.signal,
99
+ };
100
+ // Attach body if present
101
+ if (data != null) {
102
+ if (isFormData) {
103
+ // Pass FormData directly (works for both Node.js form-data and native FormData)
104
+ fetchOptions.body = data;
105
+ }
106
+ else {
107
+ fetchOptions.body = JSON.stringify(data);
108
+ }
109
+ }
110
+ try {
111
+ const response = await fetch(fullUrl, fetchOptions);
112
+ if (!response.ok) {
113
+ // Try to parse error body for a meaningful message
114
+ let errorMessage = "API Error";
115
+ try {
116
+ const errorBody = (await response.json());
117
+ errorMessage =
118
+ errorBody.error?.message || errorBody.message || "API Error";
119
+ }
120
+ catch {
121
+ // JSON parse failed, use status text
122
+ errorMessage = response.statusText || "API Error";
123
+ }
124
+ throw new Error(errorMessage);
125
+ }
126
+ // Handle 204 No Content
127
+ if (response.status === 204) {
128
+ return {};
129
+ }
130
+ const json = await response.json();
131
+ const body = json;
132
+ // Normalize response shape to { success, data, message, timestamp }.
133
+ // API responses come in several shapes depending on the service/gateway:
134
+ // 1. { success, data, message, timestamp } — standard ResponseInterceptor
135
+ // 2. { data: { ... } } — partial wrapper (no success)
136
+ // 3. { agents, pagination } — raw unwrapped
137
+ let normalized;
138
+ if (body['success'] !== undefined) {
139
+ // Case 1: fully wrapped
140
+ normalized = json;
141
+ }
142
+ else if (body['data'] !== undefined && Object.keys(body).length <= 3) {
143
+ // Case 2: has { data } wrapper but no success — add success
144
+ normalized = {
145
+ success: true,
146
+ data: body['data'],
147
+ message: body['message'] || 'Success',
148
+ timestamp: body['timestamp'] || new Date().toISOString(),
149
+ };
150
+ }
151
+ else {
152
+ // Case 3: raw unwrapped — wrap entire body as data
153
+ normalized = {
154
+ success: true,
155
+ data: json,
156
+ message: 'Success',
157
+ timestamp: new Date().toISOString(),
158
+ };
159
+ }
160
+ // Normalize _id → id in response data
161
+ if (normalized.data !== undefined) {
162
+ normalized.data = this.normalizeIds(normalized.data);
163
+ }
164
+ // Unwrap single-entity responses: { agent: {...} } → {...}
165
+ // API get-by-id endpoints return { entityName: { ...entity } }.
166
+ // Unwrap so consumers get the entity directly as `data`.
167
+ if (normalized.data !== null && typeof normalized.data === 'object' && !Array.isArray(normalized.data)) {
168
+ const dataObj = normalized.data;
169
+ const keys = Object.keys(dataObj);
170
+ const singleKey = keys.length === 1 ? keys[0] : undefined;
171
+ if (singleKey) {
172
+ const value = dataObj[singleKey];
173
+ if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
174
+ normalized.data = value;
175
+ }
176
+ }
177
+ }
178
+ return normalized;
179
+ }
180
+ catch (error) {
181
+ if (error instanceof DOMException && error.name === "AbortError") {
182
+ throw new Error(`Request timeout after ${timeout}ms`);
183
+ }
184
+ // Re-throw errors we already created above, or wrap unknown errors
185
+ if (error instanceof Error) {
186
+ throw error;
187
+ }
188
+ throw new Error("Network Error");
189
+ }
190
+ finally {
191
+ clearTimeout(timeoutId);
192
+ }
193
+ }
194
+ /**
195
+ * Make a streaming request that returns the raw Response.
196
+ *
197
+ * Unlike `request()`, this does NOT parse JSON or apply timeout.
198
+ * The caller reads `response.body` via `getReader()`.
199
+ * Used for SSE / chunked-transfer endpoints (e.g., chat streaming).
200
+ */
201
+ async requestStream(method, url, data) {
202
+ const fullUrl = new URL(url, this.config.baseUrl).toString();
203
+ const headers = {
204
+ ...this.config.headers,
205
+ 'Content-Type': 'application/json',
206
+ 'Accept': 'text/event-stream',
207
+ };
208
+ if (this.config.apiKey) {
209
+ headers['X-API-Key'] = this.config.apiKey;
210
+ }
211
+ else if (this.config.jwtToken) {
212
+ headers['Authorization'] = `Bearer ${this.config.jwtToken}`;
213
+ }
214
+ if (this.config.workspaceId) {
215
+ headers['x-workspace-id'] = this.config.workspaceId;
216
+ }
217
+ const fetchOptions = {
218
+ method,
219
+ headers,
220
+ };
221
+ if (data != null) {
222
+ fetchOptions.body = JSON.stringify(data);
223
+ }
224
+ const response = await fetch(fullUrl, fetchOptions);
225
+ if (!response.ok) {
226
+ let errorMessage = 'API Error';
227
+ try {
228
+ const errorBody = (await response.json());
229
+ errorMessage =
230
+ errorBody.error?.message || errorBody.message || 'API Error';
231
+ }
232
+ catch {
233
+ errorMessage = response.statusText || 'API Error';
234
+ }
235
+ throw new Error(errorMessage);
236
+ }
237
+ return response;
238
+ }
239
+ /**
240
+ * Recursively normalize _id → id in response data.
241
+ * Skips if id already exists to avoid overwriting.
242
+ */
243
+ normalizeIds(data) {
244
+ if (data === null || data === undefined || typeof data !== "object") {
245
+ return data;
246
+ }
247
+ if (Array.isArray(data)) {
248
+ return data.map((item) => this.normalizeIds(item));
249
+ }
250
+ const obj = data;
251
+ const result = {};
252
+ for (const [key, value] of Object.entries(obj)) {
253
+ if (key === "_id" && !("id" in obj)) {
254
+ result["id"] = value;
255
+ }
256
+ else if (key === "_id" && "id" in obj) {
257
+ // Skip _id when id already exists
258
+ continue;
259
+ }
260
+ else {
261
+ result[key] = this.normalizeIds(value);
262
+ }
263
+ }
264
+ return result;
265
+ }
266
+ /**
267
+ * Update authentication credentials
268
+ */
269
+ updateAuth(authConfig) {
270
+ if (authConfig.apiKey) {
271
+ this.config.apiKey = authConfig.apiKey;
272
+ delete this.config.jwtToken;
273
+ }
274
+ else if (authConfig.jwtToken) {
275
+ this.config.jwtToken = authConfig.jwtToken;
276
+ delete this.config.apiKey;
277
+ }
278
+ }
279
+ /**
280
+ * Get current configuration
281
+ */
282
+ getConfig() {
283
+ return { ...this.config };
284
+ }
285
+ /**
286
+ * Enable/disable debug logging
287
+ */
288
+ setDebug(enabled) {
289
+ this.config.debug = enabled;
290
+ }
291
+ }
292
+ exports.ChanlSDK = ChanlSDK;
293
+ //# sourceMappingURL=client.js.map