@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,76 @@
1
+ import { ChanlSDK } from '../client';
2
+ import { ApiResponse } from '../types/config';
3
+ export interface ApiKey {
4
+ id: string;
5
+ name: string;
6
+ key: string;
7
+ workspaceId: string;
8
+ userId: string;
9
+ permissions: string[];
10
+ createdAt: string;
11
+ lastUsed?: string;
12
+ }
13
+ export interface CreateApiKeyRequest {
14
+ name: string;
15
+ workspaceId: string;
16
+ userId: string;
17
+ permissions?: string[];
18
+ }
19
+ export interface AuthTokenResponse {
20
+ accessToken: string;
21
+ refreshToken: string;
22
+ expiresIn: number;
23
+ user: {
24
+ id: string;
25
+ email: string;
26
+ displayName?: string;
27
+ };
28
+ defaultWorkspaceId?: string;
29
+ workspaces?: Array<{
30
+ workspaceId: string;
31
+ name?: string;
32
+ role: string;
33
+ }>;
34
+ }
35
+ export declare class AuthModule {
36
+ private sdk;
37
+ constructor(sdk: ChanlSDK);
38
+ /**
39
+ * Exchange a Firebase ID token for platform JWT tokens.
40
+ * Used by CLI browser login flow.
41
+ */
42
+ exchangeFirebaseToken(firebaseToken: string): Promise<ApiResponse<AuthTokenResponse>>;
43
+ /**
44
+ * Refresh an access token using a refresh token.
45
+ */
46
+ refreshToken(refreshToken: string): Promise<ApiResponse<{
47
+ accessToken: string;
48
+ refreshToken: string;
49
+ expiresIn: number;
50
+ }>>;
51
+ /**
52
+ * Create a new API key
53
+ */
54
+ createApiKey(data: CreateApiKeyRequest): Promise<ApiResponse<ApiKey>>;
55
+ /**
56
+ * Get all API keys
57
+ */
58
+ getApiKeys(params?: {
59
+ workspaceId?: string;
60
+ userId?: string;
61
+ }): Promise<ApiResponse<ApiKey[]>>;
62
+ /**
63
+ * Revoke API key
64
+ */
65
+ revokeApiKey(keyId: string): Promise<ApiResponse<void>>;
66
+ /**
67
+ * Validate API key
68
+ */
69
+ validateApiKey(apiKey: string): Promise<ApiResponse<{
70
+ valid: boolean;
71
+ workspaceId?: string;
72
+ userId?: string;
73
+ permissions?: string[];
74
+ }>>;
75
+ }
76
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthModule = void 0;
4
+ class AuthModule {
5
+ constructor(sdk) {
6
+ this.sdk = sdk;
7
+ }
8
+ /**
9
+ * Exchange a Firebase ID token for platform JWT tokens.
10
+ * Used by CLI browser login flow.
11
+ */
12
+ async exchangeFirebaseToken(firebaseToken) {
13
+ return this.sdk.request('POST', '/api/v1/auth/firebase/exchange', {
14
+ firebaseToken,
15
+ });
16
+ }
17
+ /**
18
+ * Refresh an access token using a refresh token.
19
+ */
20
+ async refreshToken(refreshToken) {
21
+ return this.sdk.request('POST', '/api/v1/auth/token/refresh', {
22
+ refreshToken,
23
+ });
24
+ }
25
+ /**
26
+ * Create a new API key
27
+ */
28
+ async createApiKey(data) {
29
+ return this.sdk.request('POST', '/api/v1/auth/api-keys', data);
30
+ }
31
+ /**
32
+ * Get all API keys
33
+ */
34
+ async getApiKeys(params) {
35
+ const queryParams = new URLSearchParams();
36
+ if (params?.workspaceId) {
37
+ queryParams.append('workspaceId', params.workspaceId);
38
+ }
39
+ if (params?.userId) {
40
+ queryParams.append('userId', params.userId);
41
+ }
42
+ const url = `/api/v1/auth/api-keys${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
43
+ return this.sdk.request('GET', url);
44
+ }
45
+ /**
46
+ * Revoke API key
47
+ */
48
+ async revokeApiKey(keyId) {
49
+ return this.sdk.request('DELETE', `/api/v1/auth/api-keys/${keyId}`);
50
+ }
51
+ /**
52
+ * Validate API key
53
+ */
54
+ async validateApiKey(apiKey) {
55
+ return this.sdk.request('POST', '/api/v1/auth/validate', { apiKey });
56
+ }
57
+ }
58
+ exports.AuthModule = AuthModule;
59
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1,164 @@
1
+ /**
2
+ * ChatModule - SDK module for chat session management
3
+ *
4
+ * Provides operations for creating and managing text chat sessions
5
+ * with AI agents. This is the canonical way to test an agent via text:
6
+ * the platform owns the full lifecycle (interaction, transcript,
7
+ * billing, evaluation) so the SDK only deals with sessions and messages.
8
+ */
9
+ import { ChanlSDK } from '../client';
10
+ import { ApiResponse } from '../types/config';
11
+ import { ToolCall } from '../types/tool-calls';
12
+ export interface CreateChatSessionInput {
13
+ /** System prompt override */
14
+ systemPrompt?: string;
15
+ /** Variables for prompt substitution */
16
+ variables?: Record<string, string>;
17
+ /** Customer ID for memory retrieval */
18
+ customerId?: string;
19
+ /** HMAC hash for customer identity verification */
20
+ userHash?: string;
21
+ /** Additional metadata */
22
+ metadata?: Record<string, unknown>;
23
+ /** Scorecard ID for post-chat evaluation (JWT only) */
24
+ scorecardId?: string;
25
+ /** Mark as internal/test interaction (JWT only) */
26
+ internal?: boolean;
27
+ /** How systemPrompt interacts with agent prompt (JWT only) */
28
+ promptOverrideMode?: 'replace' | 'prepend' | 'append';
29
+ }
30
+ export interface ChatSessionResponse {
31
+ interactionId: string;
32
+ sessionId: string;
33
+ agentId: string;
34
+ agentName?: string;
35
+ model?: string;
36
+ createdAt: string;
37
+ }
38
+ export interface ChatMessageResponse {
39
+ sessionId: string;
40
+ message: string;
41
+ toolCalls?: ToolCall[];
42
+ latencyMs?: number;
43
+ }
44
+ export interface ChatMessage {
45
+ role: 'user' | 'assistant' | 'system';
46
+ content: string;
47
+ timestamp?: string;
48
+ }
49
+ export interface ChatMessagesResponse {
50
+ sessionId: string;
51
+ messages: ChatMessage[];
52
+ toolCalls?: ToolCall[];
53
+ }
54
+ export interface EndChatResponse {
55
+ sessionId: string;
56
+ success: boolean;
57
+ }
58
+ export interface DeleteChatResponse {
59
+ deleted: boolean;
60
+ interactionId: string;
61
+ }
62
+ import { LiveChat } from '../live/live-chat';
63
+ export declare class ChatModule {
64
+ private sdk;
65
+ constructor(sdk: ChanlSDK);
66
+ /**
67
+ * Create a new chat session with an agent
68
+ *
69
+ * The platform manages the session lifecycle including transcription,
70
+ * billing, and post-chat evaluation.
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const { data } = await sdk.chat.createSession('ws_123', 'agent_abc', {
75
+ * internal: true,
76
+ * scorecardId: 'sc_456'
77
+ * });
78
+ * console.log('Session:', data.sessionId);
79
+ * ```
80
+ */
81
+ createSession(agentId: string, options?: CreateChatSessionInput): Promise<ApiResponse<ChatSessionResponse>>;
82
+ /**
83
+ * Send a message to an active chat session
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const { data } = await sdk.chat.sendMessage('ws_123', 'session_abc', 'Hello!');
88
+ * console.log('Reply:', data.message);
89
+ * ```
90
+ */
91
+ sendMessage(sessionId: string, message: string): Promise<ApiResponse<ChatMessageResponse>>;
92
+ /**
93
+ * Send a message and stream the response in real time.
94
+ *
95
+ * The backend uses Vercel AI SDK's `pipeTextStreamToResponse()` which
96
+ * sends raw UTF-8 text chunks (not SSE JSON). Each chunk is forwarded
97
+ * to the `onChunk` callback as it arrives.
98
+ *
99
+ * Note: Streaming returns `{ message, latencyMs }` only — tool calls
100
+ * and usage metadata are not available in the stream. Use `sendMessage()`
101
+ * for full metadata, or fetch message history after streaming completes.
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * const response = await sdk.chat.streamMessage('ws_123', 'session_abc', 'Hello!', (chunk) => {
106
+ * process.stdout.write(chunk);
107
+ * });
108
+ * console.log('\nFull response:', response.data.message);
109
+ * ```
110
+ */
111
+ streamMessage(sessionId: string, message: string, onChunk: (text: string) => void): Promise<ApiResponse<ChatMessageResponse>>;
112
+ /**
113
+ * Get message history for a chat session
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * const { data } = await sdk.chat.getMessages('ws_123', 'session_abc');
118
+ * data.messages.forEach(m => console.log(`${m.role}: ${m.content}`));
119
+ * ```
120
+ */
121
+ getMessages(sessionId: string): Promise<ApiResponse<ChatMessagesResponse>>;
122
+ /**
123
+ * End a chat session
124
+ *
125
+ * Finalizes the session, creating a transcript and triggering
126
+ * evaluation if a scorecard is configured.
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * const { data } = await sdk.chat.endSession('ws_123', 'session_abc');
131
+ * console.log('Ended:', data.success);
132
+ * ```
133
+ */
134
+ endSession(sessionId: string, options?: {
135
+ scorecardId?: string;
136
+ }): Promise<ApiResponse<EndChatResponse>>;
137
+ /**
138
+ * Delete a chat session and all associated data
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * const { data } = await sdk.chat.deleteSession('ws_123', 'session_abc');
143
+ * console.log('Deleted:', data.deleted);
144
+ * ```
145
+ */
146
+ deleteSession(sessionId: string): Promise<ApiResponse<DeleteChatResponse>>;
147
+ /**
148
+ * Create a chat session and return a LiveChat wrapper
149
+ *
150
+ * Combines `createSession()` with event-driven messaging. The returned
151
+ * `LiveChat` emits events for messages and session lifecycle.
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * const chat = await sdk.chat.session('agent_abc');
156
+ * chat.on('message', (msg) => console.log('Agent:', msg.message));
157
+ *
158
+ * const reply = await chat.send('Hello!');
159
+ * await chat.end();
160
+ * ```
161
+ */
162
+ session(agentId: string, options?: CreateChatSessionInput): Promise<LiveChat>;
163
+ }
164
+ //# sourceMappingURL=chat.d.ts.map
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ /**
3
+ * ChatModule - SDK module for chat session management
4
+ *
5
+ * Provides operations for creating and managing text chat sessions
6
+ * with AI agents. This is the canonical way to test an agent via text:
7
+ * the platform owns the full lifecycle (interaction, transcript,
8
+ * billing, evaluation) so the SDK only deals with sessions and messages.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.ChatModule = void 0;
12
+ // ============================================================================
13
+ // MODULE
14
+ // ============================================================================
15
+ const live_chat_1 = require("../live/live-chat");
16
+ class ChatModule {
17
+ constructor(sdk) {
18
+ this.sdk = sdk;
19
+ }
20
+ /**
21
+ * Create a new chat session with an agent
22
+ *
23
+ * The platform manages the session lifecycle including transcription,
24
+ * billing, and post-chat evaluation.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const { data } = await sdk.chat.createSession('ws_123', 'agent_abc', {
29
+ * internal: true,
30
+ * scorecardId: 'sc_456'
31
+ * });
32
+ * console.log('Session:', data.sessionId);
33
+ * ```
34
+ */
35
+ async createSession(agentId, options) {
36
+ return this.sdk.request('POST', `/api/v1/interactions/chat?agentId=${encodeURIComponent(agentId)}`, options || {});
37
+ }
38
+ /**
39
+ * Send a message to an active chat session
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const { data } = await sdk.chat.sendMessage('ws_123', 'session_abc', 'Hello!');
44
+ * console.log('Reply:', data.message);
45
+ * ```
46
+ */
47
+ async sendMessage(sessionId, message) {
48
+ return this.sdk.request('POST', `/api/v1/interactions/${sessionId}/message`, { message });
49
+ }
50
+ /**
51
+ * Send a message and stream the response in real time.
52
+ *
53
+ * The backend uses Vercel AI SDK's `pipeTextStreamToResponse()` which
54
+ * sends raw UTF-8 text chunks (not SSE JSON). Each chunk is forwarded
55
+ * to the `onChunk` callback as it arrives.
56
+ *
57
+ * Note: Streaming returns `{ message, latencyMs }` only — tool calls
58
+ * and usage metadata are not available in the stream. Use `sendMessage()`
59
+ * for full metadata, or fetch message history after streaming completes.
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * const response = await sdk.chat.streamMessage('ws_123', 'session_abc', 'Hello!', (chunk) => {
64
+ * process.stdout.write(chunk);
65
+ * });
66
+ * console.log('\nFull response:', response.data.message);
67
+ * ```
68
+ */
69
+ async streamMessage(sessionId, message, onChunk) {
70
+ const startTime = Date.now();
71
+ const response = await this.sdk.requestStream('POST', `/api/v1/interactions/${sessionId}/message?stream=true`, { message });
72
+ const body = response.body;
73
+ if (!body) {
74
+ throw new Error('No response body for stream');
75
+ }
76
+ const reader = body.getReader();
77
+ const decoder = new TextDecoder();
78
+ let fullText = '';
79
+ try {
80
+ for (;;) {
81
+ const { done, value } = await reader.read();
82
+ if (done)
83
+ break;
84
+ const chunk = decoder.decode(value, { stream: true });
85
+ if (chunk) {
86
+ fullText += chunk;
87
+ onChunk(chunk);
88
+ }
89
+ }
90
+ }
91
+ finally {
92
+ reader.releaseLock();
93
+ }
94
+ return {
95
+ success: true,
96
+ data: {
97
+ sessionId,
98
+ message: fullText,
99
+ latencyMs: Date.now() - startTime,
100
+ },
101
+ message: 'Success',
102
+ timestamp: new Date().toISOString(),
103
+ };
104
+ }
105
+ /**
106
+ * Get message history for a chat session
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * const { data } = await sdk.chat.getMessages('ws_123', 'session_abc');
111
+ * data.messages.forEach(m => console.log(`${m.role}: ${m.content}`));
112
+ * ```
113
+ */
114
+ async getMessages(sessionId) {
115
+ return this.sdk.request('GET', `/api/v1/interactions/${sessionId}/messages`);
116
+ }
117
+ /**
118
+ * End a chat session
119
+ *
120
+ * Finalizes the session, creating a transcript and triggering
121
+ * evaluation if a scorecard is configured.
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * const { data } = await sdk.chat.endSession('ws_123', 'session_abc');
126
+ * console.log('Ended:', data.success);
127
+ * ```
128
+ */
129
+ async endSession(sessionId, options) {
130
+ return this.sdk.request('POST', `/api/v1/interactions/${sessionId}/end`, options || {});
131
+ }
132
+ /**
133
+ * Delete a chat session and all associated data
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * const { data } = await sdk.chat.deleteSession('ws_123', 'session_abc');
138
+ * console.log('Deleted:', data.deleted);
139
+ * ```
140
+ */
141
+ async deleteSession(sessionId) {
142
+ return this.sdk.request('DELETE', `/api/v1/interactions/${sessionId}/chat`);
143
+ }
144
+ /**
145
+ * Create a chat session and return a LiveChat wrapper
146
+ *
147
+ * Combines `createSession()` with event-driven messaging. The returned
148
+ * `LiveChat` emits events for messages and session lifecycle.
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * const chat = await sdk.chat.session('agent_abc');
153
+ * chat.on('message', (msg) => console.log('Agent:', msg.message));
154
+ *
155
+ * const reply = await chat.send('Hello!');
156
+ * await chat.end();
157
+ * ```
158
+ */
159
+ async session(agentId, options) {
160
+ const response = await this.createSession(agentId, options);
161
+ if (!response.success || !response.data) {
162
+ throw new Error(response.message || 'Failed to create chat session');
163
+ }
164
+ return new live_chat_1.LiveChat(this.sdk, response.data);
165
+ }
166
+ }
167
+ exports.ChatModule = ChatModule;
168
+ //# sourceMappingURL=chat.js.map
@@ -0,0 +1,45 @@
1
+ import { ChanlSDK } from '../client';
2
+ import { ApiResponse } from '../types/config';
3
+ export interface HealthStatus {
4
+ status: 'healthy' | 'unhealthy' | 'ok';
5
+ timestamp: string;
6
+ version: string;
7
+ uptime: number;
8
+ }
9
+ export interface DetailedHealthStatus {
10
+ status: 'healthy' | 'unhealthy' | 'ok';
11
+ timestamp: string;
12
+ version: string;
13
+ uptime: number;
14
+ components: {
15
+ database: {
16
+ status: 'healthy' | 'unhealthy';
17
+ responseTime: number;
18
+ };
19
+ redis?: {
20
+ status: 'healthy' | 'unhealthy';
21
+ responseTime: number;
22
+ };
23
+ deepgram?: {
24
+ status: 'healthy' | 'unhealthy';
25
+ responseTime: number;
26
+ };
27
+ openai?: {
28
+ status: 'healthy' | 'unhealthy';
29
+ responseTime: number;
30
+ };
31
+ };
32
+ }
33
+ export declare class HealthModule {
34
+ private sdk;
35
+ constructor(sdk: ChanlSDK);
36
+ /**
37
+ * Get basic health status
38
+ */
39
+ getHealth(): Promise<ApiResponse<HealthStatus>>;
40
+ /**
41
+ * Get detailed health status
42
+ */
43
+ getDetailedHealth(): Promise<ApiResponse<DetailedHealthStatus>>;
44
+ }
45
+ //# sourceMappingURL=health.d.ts.map
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HealthModule = void 0;
4
+ class HealthModule {
5
+ constructor(sdk) {
6
+ this.sdk = sdk;
7
+ }
8
+ /**
9
+ * Get basic health status
10
+ */
11
+ async getHealth() {
12
+ return this.sdk.request('GET', '/health');
13
+ }
14
+ /**
15
+ * Get detailed health status
16
+ */
17
+ async getDetailedHealth() {
18
+ return this.sdk.request('GET', '/health/ready');
19
+ }
20
+ }
21
+ exports.HealthModule = HealthModule;
22
+ //# sourceMappingURL=health.js.map