@skillful-ai/skai-sdk 1.0.2
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/package.json +34 -0
- package/src/clients/admin-client.d.ts +33 -0
- package/src/clients/admin-client.js +41 -0
- package/src/clients/admin-client.js.map +1 -0
- package/src/clients/agents-client.d.ts +98 -0
- package/src/clients/agents-client.js +344 -0
- package/src/clients/agents-client.js.map +1 -0
- package/src/clients/base-client.d.ts +22 -0
- package/src/clients/base-client.js +148 -0
- package/src/clients/base-client.js.map +1 -0
- package/src/clients/index.d.ts +3 -0
- package/src/clients/index.js +7 -0
- package/src/clients/index.js.map +1 -0
- package/src/constants.d.ts +6 -0
- package/src/constants.js +13 -0
- package/src/constants.js.map +1 -0
- package/src/errors.d.ts +18 -0
- package/src/errors.js +23 -0
- package/src/errors.js.map +1 -0
- package/src/index.d.ts +37 -0
- package/src/index.js +50 -0
- package/src/index.js.map +1 -0
- package/src/streaming/index.d.ts +6 -0
- package/src/streaming/index.js +13 -0
- package/src/streaming/index.js.map +1 -0
- package/src/types/admin-api-types.d.ts +46 -0
- package/src/types/admin-api-types.js +32 -0
- package/src/types/admin-api-types.js.map +1 -0
- package/src/types/agents-api-types.d.ts +192 -0
- package/src/types/agents-api-types.js +135 -0
- package/src/types/agents-api-types.js.map +1 -0
- package/src/types/api-types.d.ts +20 -0
- package/src/types/api-types.js +12 -0
- package/src/types/api-types.js.map +1 -0
- package/src/types/index.d.ts +3 -0
- package/src/types/index.js +7 -0
- package/src/types/index.js.map +1 -0
- package/src/types/streaming.d.ts +109 -0
- package/src/types/streaming.js +55 -0
- package/src/types/streaming.js.map +1 -0
- package/src/utils/index.d.ts +1 -0
- package/src/utils/index.js +5 -0
- package/src/utils/index.js.map +1 -0
- package/src/utils/logger-adapter.d.ts +7 -0
- package/src/utils/logger-adapter.js +54 -0
- package/src/utils/logger-adapter.js.map +1 -0
- package/src/utils/skai-helpers.d.ts +19 -0
- package/src/utils/skai-helpers.js +47 -0
- package/src/utils/skai-helpers.js.map +1 -0
- package/src/utils/stream-metrics.d.ts +55 -0
- package/src/utils/stream-metrics.js +132 -0
- package/src/utils/stream-metrics.js.map +1 -0
- package/src/utils/stream-parser.d.ts +49 -0
- package/src/utils/stream-parser.js +181 -0
- package/src/utils/stream-parser.js.map +1 -0
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@skillful-ai/skai-sdk",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "SKAI SDK for interacting with Skillful AI Agents API",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"types": "./src/index.d.ts",
|
|
7
|
+
"type": "commonjs",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@sinclair/typebox": "0.34.11",
|
|
10
|
+
"axios": "^1.8.3",
|
|
11
|
+
"fastify": "5.4.0",
|
|
12
|
+
"tslib": "^2.3.0"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"skai",
|
|
16
|
+
"skillful",
|
|
17
|
+
"ai",
|
|
18
|
+
"agents",
|
|
19
|
+
"sdk"
|
|
20
|
+
],
|
|
21
|
+
"author": "Skillful AI",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"overrides": {
|
|
24
|
+
"@tryfabric/martian": {
|
|
25
|
+
"@notionhq/client": "$@notionhq/client"
|
|
26
|
+
},
|
|
27
|
+
"vite": {
|
|
28
|
+
"rollup": "npm:@rollup/wasm-node"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"resolutions": {
|
|
32
|
+
"rollup": "npm:@rollup/wasm-node"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { GetUserAPIKeyResponse, GetUserAPIKeysResponse } from '../types/admin-api-types';
|
|
2
|
+
import { Logger, SkaiBaseClient } from './base-client';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for SKAI Admin Client
|
|
5
|
+
*/
|
|
6
|
+
export interface SkaiAdminClientConfig {
|
|
7
|
+
/** Base URL for SKAI API (e.g., 'https://api-dev.agents.skillfulai.io') */
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
/** Admin API key for privileged operations */
|
|
10
|
+
adminApiKey: string;
|
|
11
|
+
/** Request timeout in milliseconds (optional, defaults to 5 minutes) */
|
|
12
|
+
timeout?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare class SkaiAdminClient extends SkaiBaseClient {
|
|
15
|
+
private readonly adminApiKey;
|
|
16
|
+
constructor(log: Logger, config: SkaiAdminClientConfig);
|
|
17
|
+
/**
|
|
18
|
+
* Get all system-managed API keys for a specific user
|
|
19
|
+
* @param userId The ID of the user whose API keys to retrieve
|
|
20
|
+
* @returns GetUserAPIKeysResponse containing the user's system-managed API keys
|
|
21
|
+
*/
|
|
22
|
+
getUserApiKeys(userId: string): Promise<GetUserAPIKeysResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Get a system-managed API key for a user
|
|
25
|
+
* @param userId The ID of the user whose API key to retrieve
|
|
26
|
+
* @returns GetUserAPIKeyResponse containing the API key
|
|
27
|
+
*/
|
|
28
|
+
getUserApiKey(userId: string): Promise<GetUserAPIKeyResponse>;
|
|
29
|
+
/**
|
|
30
|
+
* Create a new SKAI Admin client instance
|
|
31
|
+
*/
|
|
32
|
+
static create(log: Logger, config: SkaiAdminClientConfig): SkaiAdminClient;
|
|
33
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SkaiAdminClient = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const base_client_1 = require("./base-client");
|
|
6
|
+
class SkaiAdminClient extends base_client_1.SkaiBaseClient {
|
|
7
|
+
constructor(log, config) {
|
|
8
|
+
super(log, config.baseUrl, config.timeout);
|
|
9
|
+
this.adminApiKey = config.adminApiKey;
|
|
10
|
+
// Set admin API key in default headers (SKAI API uses raw API key, not Bearer token)
|
|
11
|
+
this.httpClient.defaults.headers.common['Authorization'] = this.adminApiKey;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get all system-managed API keys for a specific user
|
|
15
|
+
* @param userId The ID of the user whose API keys to retrieve
|
|
16
|
+
* @returns GetUserAPIKeysResponse containing the user's system-managed API keys
|
|
17
|
+
*/
|
|
18
|
+
getUserApiKeys(userId) {
|
|
19
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
return this.makeRequest('GET', `/admin/system-api-keys/${userId}`);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get a system-managed API key for a user
|
|
25
|
+
* @param userId The ID of the user whose API key to retrieve
|
|
26
|
+
* @returns GetUserAPIKeyResponse containing the API key
|
|
27
|
+
*/
|
|
28
|
+
getUserApiKey(userId) {
|
|
29
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
return this.makeRequest('GET', `/admin/system-api-key/${userId}`);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create a new SKAI Admin client instance
|
|
35
|
+
*/
|
|
36
|
+
static create(log, config) {
|
|
37
|
+
return new SkaiAdminClient(log, config);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.SkaiAdminClient = SkaiAdminClient;
|
|
41
|
+
//# sourceMappingURL=admin-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin-client.js","sourceRoot":"","sources":["../../../../../../packages/custom/skai-sdk/src/clients/admin-client.ts"],"names":[],"mappings":";;;;AACA,+CAAsD;AActD,MAAa,eAAgB,SAAQ,4BAAc;IAG/C,YACI,GAAW,EACX,MAA6B;QAE7B,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;QAC1C,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAA;QAErC,qFAAqF;QACrF,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC,WAAW,CAAA;IAC/E,CAAC;IAED;;;;OAIG;IACG,cAAc,CAAC,MAAc;;YAC/B,OAAO,IAAI,CAAC,WAAW,CACnB,KAAK,EACL,0BAA0B,MAAM,EAAE,CACrC,CAAA;QACL,CAAC;KAAA;IAED;;;;OAIG;IACG,aAAa,CAAC,MAAc;;YAC9B,OAAO,IAAI,CAAC,WAAW,CACnB,KAAK,EACL,yBAAyB,MAAM,EAAE,CACpC,CAAA;QACL,CAAC;KAAA;IAED;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,GAAW,EAAE,MAA6B;QACpD,OAAO,IAAI,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;IAC3C,CAAC;CACJ;AA5CD,0CA4CC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { SkaiAgent, SkaiChatRequestParams, SkaiChatResponse } from '../types/agents-api-types';
|
|
2
|
+
import { Logger, SkaiBaseClient } from './base-client';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for SKAI Agents Client
|
|
5
|
+
*/
|
|
6
|
+
export interface SkaiAgentsClientConfig {
|
|
7
|
+
/** Base URL for SKAI API (e.g., 'https://api-dev.agents.skillfulai.io') */
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
/** User API key for agent operations */
|
|
10
|
+
userApiKey: string;
|
|
11
|
+
/** Request timeout in milliseconds (optional, defaults to 5 minutes) */
|
|
12
|
+
timeout?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* SKAI Agents Client for managing SKAI AI agents and chat interactions
|
|
16
|
+
*
|
|
17
|
+
* Provides access to SKAI Agents API endpoints:
|
|
18
|
+
* - List user agents
|
|
19
|
+
* - Chat with agents (non-streaming and streaming)
|
|
20
|
+
*
|
|
21
|
+
* Usage:
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const agentsClient = new SkaiAgentsClient(log, {
|
|
24
|
+
* baseUrl: 'https://api-dev.agents.skillfulai.io',
|
|
25
|
+
* userApiKey: 'sk-...'
|
|
26
|
+
* })
|
|
27
|
+
*
|
|
28
|
+
* // List all agents for a user
|
|
29
|
+
* const agents = await agentsClient.listAgents()
|
|
30
|
+
*
|
|
31
|
+
* // Chat with an agent
|
|
32
|
+
* const response = await agentsClient.chat({
|
|
33
|
+
* agentId: 'agent-uuid',
|
|
34
|
+
* message: 'Hello!'
|
|
35
|
+
* })
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare class SkaiAgentsClient extends SkaiBaseClient {
|
|
39
|
+
private readonly userApiKey;
|
|
40
|
+
constructor(log: Logger, config: SkaiAgentsClientConfig);
|
|
41
|
+
/**
|
|
42
|
+
* List all agents for the authenticated user
|
|
43
|
+
* GET /api/agents
|
|
44
|
+
*
|
|
45
|
+
* @returns Array of user's agents
|
|
46
|
+
*/
|
|
47
|
+
listAgents(): Promise<SkaiAgent[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Get a specific agent by ID
|
|
50
|
+
* GET /api/agents/{agent_id}
|
|
51
|
+
*
|
|
52
|
+
* @param agentId - The agent ID to retrieve
|
|
53
|
+
* @returns The requested agent
|
|
54
|
+
*/
|
|
55
|
+
getAgent(agentId: string): Promise<SkaiAgent>;
|
|
56
|
+
/**
|
|
57
|
+
* Send a message to an agent and get a complete response (non-streaming)
|
|
58
|
+
* POST /api/agents/{agent_id}/chat/message
|
|
59
|
+
* POST /api/agents/{agent_id}/chat/{chat_history_id}/message
|
|
60
|
+
*
|
|
61
|
+
* @param params - Chat request parameters
|
|
62
|
+
* @returns Complete chat response
|
|
63
|
+
*/
|
|
64
|
+
chat(params: Omit<SkaiChatRequestParams, 'apiKey'>): Promise<SkaiChatResponse>;
|
|
65
|
+
/**
|
|
66
|
+
* Send a message to an agent using streaming (avoids API gateway timeouts)
|
|
67
|
+
* POST /api/agents/{agent_id}/chat
|
|
68
|
+
* POST /api/agents/{agent_id}/chat/{chat_history_id}
|
|
69
|
+
*
|
|
70
|
+
* @param params - Chat request parameters
|
|
71
|
+
* @returns Complete chat response (same format as non-streaming)
|
|
72
|
+
*/
|
|
73
|
+
chatStream(params: Omit<SkaiChatRequestParams, 'apiKey'>): Promise<SkaiChatResponse>;
|
|
74
|
+
/**
|
|
75
|
+
* Send a test message to an agent using streaming (doesn't consume allowance)
|
|
76
|
+
*
|
|
77
|
+
* @param params - Test chat parameters
|
|
78
|
+
* @returns Test chat response
|
|
79
|
+
*/
|
|
80
|
+
testChatStream(params: Omit<SkaiChatRequestParams, 'apiKey' | 'isTestMode'>): Promise<SkaiChatResponse>;
|
|
81
|
+
/**
|
|
82
|
+
* Internal method to handle streaming responses from agents-api
|
|
83
|
+
* Processes Server-Sent Events and buffers complete response
|
|
84
|
+
* Returns the same format as non-streaming chat for backward compatibility
|
|
85
|
+
*/
|
|
86
|
+
private makeStreamingRequest;
|
|
87
|
+
/**
|
|
88
|
+
* Send a test message to an agent (does not consume user allowance)
|
|
89
|
+
*
|
|
90
|
+
* @param params - Test chat parameters
|
|
91
|
+
* @returns Test chat response
|
|
92
|
+
*/
|
|
93
|
+
testChat(params: Omit<SkaiChatRequestParams, 'apiKey' | 'isTestMode'>): Promise<SkaiChatResponse>;
|
|
94
|
+
/**
|
|
95
|
+
* Create a new SKAI Agents client instance
|
|
96
|
+
*/
|
|
97
|
+
static create(log: Logger, config: SkaiAgentsClientConfig): SkaiAgentsClient;
|
|
98
|
+
}
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SkaiAgentsClient = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const streaming_1 = require("../streaming");
|
|
7
|
+
const agents_api_types_1 = require("../types/agents-api-types");
|
|
8
|
+
const base_client_1 = require("./base-client");
|
|
9
|
+
/**
|
|
10
|
+
* SKAI Agents Client for managing SKAI AI agents and chat interactions
|
|
11
|
+
*
|
|
12
|
+
* Provides access to SKAI Agents API endpoints:
|
|
13
|
+
* - List user agents
|
|
14
|
+
* - Chat with agents (non-streaming and streaming)
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const agentsClient = new SkaiAgentsClient(log, {
|
|
19
|
+
* baseUrl: 'https://api-dev.agents.skillfulai.io',
|
|
20
|
+
* userApiKey: 'sk-...'
|
|
21
|
+
* })
|
|
22
|
+
*
|
|
23
|
+
* // List all agents for a user
|
|
24
|
+
* const agents = await agentsClient.listAgents()
|
|
25
|
+
*
|
|
26
|
+
* // Chat with an agent
|
|
27
|
+
* const response = await agentsClient.chat({
|
|
28
|
+
* agentId: 'agent-uuid',
|
|
29
|
+
* message: 'Hello!'
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
class SkaiAgentsClient extends base_client_1.SkaiBaseClient {
|
|
34
|
+
constructor(log, config) {
|
|
35
|
+
super(log, config.baseUrl, config.timeout);
|
|
36
|
+
this.userApiKey = config.userApiKey;
|
|
37
|
+
// Set user API key in default headers
|
|
38
|
+
this.httpClient.defaults.headers.common['Authorization'] = this.userApiKey;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* List all agents for the authenticated user
|
|
42
|
+
* GET /api/agents
|
|
43
|
+
*
|
|
44
|
+
* @returns Array of user's agents
|
|
45
|
+
*/
|
|
46
|
+
listAgents() {
|
|
47
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
try {
|
|
49
|
+
this.log.debug('Listing SKAI agents');
|
|
50
|
+
const response = yield this.makeRequest('GET', '/agents');
|
|
51
|
+
return response;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
this.log.error({
|
|
55
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
56
|
+
}, 'Failed to list SKAI agents');
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get a specific agent by ID
|
|
63
|
+
* GET /api/agents/{agent_id}
|
|
64
|
+
*
|
|
65
|
+
* @param agentId - The agent ID to retrieve
|
|
66
|
+
* @returns The requested agent
|
|
67
|
+
*/
|
|
68
|
+
getAgent(agentId) {
|
|
69
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
try {
|
|
71
|
+
const response = yield this.makeRequest('GET', `/agents/${agentId}`);
|
|
72
|
+
return response;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
this.log.error({
|
|
76
|
+
agentId,
|
|
77
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
78
|
+
}, 'Failed to get SKAI agent');
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Send a message to an agent and get a complete response (non-streaming)
|
|
85
|
+
* POST /api/agents/{agent_id}/chat/message
|
|
86
|
+
* POST /api/agents/{agent_id}/chat/{chat_history_id}/message
|
|
87
|
+
*
|
|
88
|
+
* @param params - Chat request parameters
|
|
89
|
+
* @returns Complete chat response
|
|
90
|
+
*/
|
|
91
|
+
chat(params) {
|
|
92
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
try {
|
|
94
|
+
// Build endpoint URL based on whether chat history ID is provided
|
|
95
|
+
const endpoint = params.chatHistoryId
|
|
96
|
+
? `/agents/${params.agentId}/chat/${params.chatHistoryId}/message`
|
|
97
|
+
: `/agents/${params.agentId}/chat/message`;
|
|
98
|
+
const requestBody = {
|
|
99
|
+
message: params.message,
|
|
100
|
+
isTestMode: params.isTestMode || false,
|
|
101
|
+
};
|
|
102
|
+
const response = yield this.makeRequest('POST', endpoint, requestBody, {
|
|
103
|
+
timeout: constants_1.SKAI_AGENTS_EXECUTION_TIMEOUT, // 10 minutes for agent execution
|
|
104
|
+
});
|
|
105
|
+
return response;
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
this.log.error({
|
|
109
|
+
agentId: params.agentId,
|
|
110
|
+
chatHistoryId: params.chatHistoryId,
|
|
111
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
112
|
+
}, 'Failed to chat with SKAI agent');
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Send a message to an agent using streaming (avoids API gateway timeouts)
|
|
119
|
+
* POST /api/agents/{agent_id}/chat
|
|
120
|
+
* POST /api/agents/{agent_id}/chat/{chat_history_id}
|
|
121
|
+
*
|
|
122
|
+
* @param params - Chat request parameters
|
|
123
|
+
* @returns Complete chat response (same format as non-streaming)
|
|
124
|
+
*/
|
|
125
|
+
chatStream(params) {
|
|
126
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
const startTime = Date.now();
|
|
128
|
+
try {
|
|
129
|
+
this.log.debug({
|
|
130
|
+
agentId: params.agentId,
|
|
131
|
+
chatHistoryId: params.chatHistoryId,
|
|
132
|
+
requestId: params.requestId,
|
|
133
|
+
flowId: params.flowId,
|
|
134
|
+
flowRunId: params.flowRunId,
|
|
135
|
+
}, 'Starting chat stream request');
|
|
136
|
+
// Build streaming endpoint URL (no /message suffix)
|
|
137
|
+
const endpoint = params.chatHistoryId
|
|
138
|
+
? `/agents/${params.agentId}/chat/${params.chatHistoryId}`
|
|
139
|
+
: `/agents/${params.agentId}/chat`;
|
|
140
|
+
// Convert to streaming request format
|
|
141
|
+
const requestBody = {
|
|
142
|
+
messages: [
|
|
143
|
+
{
|
|
144
|
+
role: agents_api_types_1.ChatMessageRole.USER,
|
|
145
|
+
content: params.message,
|
|
146
|
+
createdAt: new Date().toISOString(),
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
isTestMode: params.isTestMode || false,
|
|
150
|
+
};
|
|
151
|
+
// Request prepared
|
|
152
|
+
// Use internal streaming method, buffer complete response
|
|
153
|
+
const response = yield this.makeStreamingRequest('POST', endpoint, requestBody, {
|
|
154
|
+
timeout: constants_1.SKAI_AGENTS_STREAMING_TIMEOUT, // 30 minutes for streaming (avoid API gateway timeout)
|
|
155
|
+
}, params.requestId, params.flowId, params.flowRunId);
|
|
156
|
+
const duration = Date.now() - startTime;
|
|
157
|
+
this.log.debug({
|
|
158
|
+
agentId: params.agentId,
|
|
159
|
+
chatHistoryId: response.chatHistoryId,
|
|
160
|
+
responseLength: response.message.length,
|
|
161
|
+
durationMs: duration,
|
|
162
|
+
durationSeconds: (duration / 1000).toFixed(2),
|
|
163
|
+
requestId: params.requestId,
|
|
164
|
+
flowId: params.flowId,
|
|
165
|
+
flowRunId: params.flowRunId,
|
|
166
|
+
}, 'Chat stream completed successfully');
|
|
167
|
+
return response;
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
const duration = Date.now() - startTime;
|
|
171
|
+
this.log.error({
|
|
172
|
+
agentId: params.agentId,
|
|
173
|
+
chatHistoryId: params.chatHistoryId,
|
|
174
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
175
|
+
errorStack: error instanceof Error ? error.stack : undefined,
|
|
176
|
+
durationMs: duration,
|
|
177
|
+
durationSeconds: (duration / 1000).toFixed(2),
|
|
178
|
+
requestId: params.requestId,
|
|
179
|
+
flowId: params.flowId,
|
|
180
|
+
flowRunId: params.flowRunId,
|
|
181
|
+
}, 'Failed to chat with SKAI agent (streaming)');
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Send a test message to an agent using streaming (doesn't consume allowance)
|
|
188
|
+
*
|
|
189
|
+
* @param params - Test chat parameters
|
|
190
|
+
* @returns Test chat response
|
|
191
|
+
*/
|
|
192
|
+
testChatStream(params) {
|
|
193
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
194
|
+
return this.chatStream(Object.assign(Object.assign({}, params), { isTestMode: true }));
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Internal method to handle streaming responses from agents-api
|
|
199
|
+
* Processes Server-Sent Events and buffers complete response
|
|
200
|
+
* Returns the same format as non-streaming chat for backward compatibility
|
|
201
|
+
*/
|
|
202
|
+
makeStreamingRequest(method, endpoint, data, options, requestId, flowId, flowRunId) {
|
|
203
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
204
|
+
var _a;
|
|
205
|
+
const url = endpoint.startsWith('/api') ? endpoint : `/api${endpoint}`;
|
|
206
|
+
const fullUrl = `${this.baseUrl}${url}`;
|
|
207
|
+
const streamStartTime = Date.now();
|
|
208
|
+
try {
|
|
209
|
+
const response = yield fetch(fullUrl, {
|
|
210
|
+
method,
|
|
211
|
+
headers: Object.assign({ 'Content-Type': 'application/json', 'Authorization': this.userApiKey, 'User-Agent': 'Activepieces-SKAI-SDK/1.0' }, options.headers),
|
|
212
|
+
body: JSON.stringify(data),
|
|
213
|
+
});
|
|
214
|
+
// Response received
|
|
215
|
+
if (!response.ok) {
|
|
216
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
217
|
+
}
|
|
218
|
+
// Extract chat history ID from response headers
|
|
219
|
+
const chatHistoryId = response.headers.get('X-Chat-History-Id');
|
|
220
|
+
// Process streaming response
|
|
221
|
+
const reader = (_a = response.body) === null || _a === void 0 ? void 0 : _a.getReader();
|
|
222
|
+
if (!reader) {
|
|
223
|
+
throw new Error('Response body is not readable');
|
|
224
|
+
}
|
|
225
|
+
// Initialize streaming components
|
|
226
|
+
let buffer = '';
|
|
227
|
+
let completeMessage = '';
|
|
228
|
+
const decoder = new TextDecoder();
|
|
229
|
+
const metrics = new streaming_1.SkaiStreamMetricsTracker(streamStartTime);
|
|
230
|
+
try {
|
|
231
|
+
this.log.debug({
|
|
232
|
+
requestId,
|
|
233
|
+
flowId,
|
|
234
|
+
flowRunId,
|
|
235
|
+
}, 'Starting to read stream chunks');
|
|
236
|
+
// eslint-disable-next-line no-constant-condition
|
|
237
|
+
while (true) {
|
|
238
|
+
const { done, value } = yield reader.read();
|
|
239
|
+
if (done) {
|
|
240
|
+
metrics.recordCompletion();
|
|
241
|
+
this.log.debug(Object.assign(Object.assign({}, metrics.toLogObject()), { requestId,
|
|
242
|
+
flowId,
|
|
243
|
+
flowRunId }), 'Stream reading completed');
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
const chunkSize = value.byteLength;
|
|
247
|
+
metrics.recordChunk(chunkSize);
|
|
248
|
+
// Process chunks, removing "data: " prefix and parsing
|
|
249
|
+
const chunk = decoder.decode(value).replaceAll('data: ', '');
|
|
250
|
+
buffer += chunk.trimEnd();
|
|
251
|
+
// Process chunk
|
|
252
|
+
// Parse streaming tokens when we have complete data
|
|
253
|
+
if (buffer.endsWith(']') || buffer.endsWith('"')) {
|
|
254
|
+
// Split into lines and process using our modular parser
|
|
255
|
+
const lines = buffer.split('\n').filter(line => line.trim());
|
|
256
|
+
try {
|
|
257
|
+
const result = (0, streaming_1.processStreamLines)(lines);
|
|
258
|
+
// Add parsed content to complete message
|
|
259
|
+
if (result.content) {
|
|
260
|
+
completeMessage += result.content;
|
|
261
|
+
// Record tokens for metrics
|
|
262
|
+
for (let i = 0; i < result.tokens; i++) {
|
|
263
|
+
metrics.recordToken(result.content);
|
|
264
|
+
}
|
|
265
|
+
// Token parsed
|
|
266
|
+
}
|
|
267
|
+
// Buffer processed
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
// Handle parsing errors (including SKAI stream errors)
|
|
271
|
+
if (error instanceof streaming_1.SkaiStreamError) {
|
|
272
|
+
this.log.error({
|
|
273
|
+
errorMessage: error.message,
|
|
274
|
+
tokenData: error.tokenData,
|
|
275
|
+
}, 'SKAI agent error detected - terminating stream');
|
|
276
|
+
throw error;
|
|
277
|
+
}
|
|
278
|
+
// Log other parsing errors but continue
|
|
279
|
+
this.log.warn({
|
|
280
|
+
error: error instanceof Error ? error.message : 'Unknown parsing error',
|
|
281
|
+
linesCount: lines.length,
|
|
282
|
+
}, 'Failed to parse some stream lines');
|
|
283
|
+
}
|
|
284
|
+
buffer = '';
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
finally {
|
|
289
|
+
reader.releaseLock();
|
|
290
|
+
}
|
|
291
|
+
// Log completion with metrics
|
|
292
|
+
this.log.debug(Object.assign(Object.assign({ chatHistoryId: chatHistoryId || 'unknown', messageLength: completeMessage.trim().length }, metrics.toLogObject()), { requestId,
|
|
293
|
+
flowId,
|
|
294
|
+
flowRunId }), 'Stream processing completed');
|
|
295
|
+
// Validate stream completion using our modular validator
|
|
296
|
+
(0, streaming_1.validateStreamCompletion)(metrics.getMetrics().totalTokens, completeMessage.trim().length);
|
|
297
|
+
return {
|
|
298
|
+
chatHistoryId: chatHistoryId || 'unknown',
|
|
299
|
+
message: completeMessage.trim(),
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
catch (error) {
|
|
303
|
+
const errorDuration = Date.now() - streamStartTime;
|
|
304
|
+
// Enhanced error logging with proper error classification
|
|
305
|
+
const isSkaiError = error instanceof streaming_1.SkaiStreamError ||
|
|
306
|
+
error instanceof streaming_1.SkaiStreamTimeoutError ||
|
|
307
|
+
error instanceof streaming_1.SkaiStreamValidationError;
|
|
308
|
+
this.log.error({
|
|
309
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
310
|
+
errorType: error instanceof Error ? error.constructor.name : 'UnknownError',
|
|
311
|
+
errorStack: error instanceof Error ? error.stack : undefined,
|
|
312
|
+
isSkaiError,
|
|
313
|
+
url: fullUrl,
|
|
314
|
+
endpoint,
|
|
315
|
+
durationMs: errorDuration,
|
|
316
|
+
durationSeconds: (errorDuration / 1000).toFixed(2),
|
|
317
|
+
requestId,
|
|
318
|
+
flowId,
|
|
319
|
+
flowRunId,
|
|
320
|
+
}, `SKAI API streaming ${method} ${url} - ${isSkaiError ? 'Agent Error' : 'Failed'}`);
|
|
321
|
+
throw error;
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Send a test message to an agent (does not consume user allowance)
|
|
327
|
+
*
|
|
328
|
+
* @param params - Test chat parameters
|
|
329
|
+
* @returns Test chat response
|
|
330
|
+
*/
|
|
331
|
+
testChat(params) {
|
|
332
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
333
|
+
return this.chat(Object.assign(Object.assign({}, params), { isTestMode: true }));
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Create a new SKAI Agents client instance
|
|
338
|
+
*/
|
|
339
|
+
static create(log, config) {
|
|
340
|
+
return new SkaiAgentsClient(log, config);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
exports.SkaiAgentsClient = SkaiAgentsClient;
|
|
344
|
+
//# sourceMappingURL=agents-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents-client.js","sourceRoot":"","sources":["../../../../../../packages/custom/skai-sdk/src/clients/agents-client.ts"],"names":[],"mappings":";;;;AAAA,4CAA2F;AAC3F,4CAOqB;AACrB,gEAQkC;AAElC,+CAAsD;AActD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAa,gBAAiB,SAAQ,4BAAc;IAGhD,YACI,GAAW,EACX,MAA8B;QAE9B,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;QAC1C,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;QAEnC,sCAAsC;QACtC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC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KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;oBAC/D,SAAS,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc;oBAC3E,UAAU,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;oBAC5D,WAAW;oBACX,GAAG,EAAE,OAAO;oBACZ,QAAQ;oBACR,UAAU,EAAE,aAAa;oBACzB,eAAe,EAAE,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;oBAClD,SAAS;oBACT,MAAM;oBACN,SAAS;iBACZ,EAAE,sBAAsB,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;gBACrF,MAAM,KAAK,CAAA;YACf,CAAC;QACL,CAAC;KAAA;IAED;;;;;OAKG;IACG,QAAQ,CAAC,MAA4D;;YACvE,OAAO,IAAI,CAAC,IAAI,iCACT,MAAM,KACT,UAAU,EAAE,IAAI,IAClB,CAAA;QACN,CAAC;KAAA;IAED;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,GAAW,EAAE,MAA8B;QACrD,OAAO,IAAI,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;IAC5C,CAAC;CACJ;AA1YD,4CA0YC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { SkaiApiRequestOptions } from '../types';
|
|
3
|
+
export interface Logger {
|
|
4
|
+
debug(objectOrMessage: object | string, message?: string): void;
|
|
5
|
+
info(objectOrMessage: object | string, message?: string): void;
|
|
6
|
+
warn(objectOrMessage: object | string, message?: string): void;
|
|
7
|
+
error(objectOrMessage: object | string, message?: string): void;
|
|
8
|
+
}
|
|
9
|
+
export declare const consoleLogger: Logger;
|
|
10
|
+
export declare abstract class SkaiBaseClient {
|
|
11
|
+
protected readonly log: Logger;
|
|
12
|
+
protected readonly baseUrl: string;
|
|
13
|
+
protected readonly timeout: number;
|
|
14
|
+
protected readonly httpClient: AxiosInstance;
|
|
15
|
+
constructor(log: Logger, baseUrl: string, timeout?: number);
|
|
16
|
+
private setupErrorInterceptor;
|
|
17
|
+
healthCheck(): Promise<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Make a request to the SKAI API
|
|
20
|
+
*/
|
|
21
|
+
protected makeRequest<T>(method: 'GET' | 'POST' | 'PUT' | 'DELETE', endpoint: string, data?: unknown, options?: SkaiApiRequestOptions): Promise<T>;
|
|
22
|
+
}
|