@butlerbot/sdk 0.0.10 → 0.0.12
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/dist/config.d.ts +2 -1
- package/dist/config.js +5 -2
- package/dist/modules/conversation.d.ts +16 -8
- package/dist/modules/conversation.js +37 -10
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
package/dist/config.js
CHANGED
|
@@ -17,8 +17,11 @@ exports.CONFIG = {
|
|
|
17
17
|
v1: { base: "/api/convo/get/history" }
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
|
-
|
|
21
|
-
v4: {
|
|
20
|
+
progress: {
|
|
21
|
+
v4: {
|
|
22
|
+
base: "/api/alfred/v4/chat/progress",
|
|
23
|
+
stream: "/api/alfred/v4/chat/progress/stream",
|
|
24
|
+
}
|
|
22
25
|
},
|
|
23
26
|
usage: {
|
|
24
27
|
policy: {
|
|
@@ -34,8 +34,10 @@ export type ConversationOptions = {
|
|
|
34
34
|
convoPath?: string;
|
|
35
35
|
/** The path to append to the server URL specifying the history API endpoint to use */
|
|
36
36
|
historyPath?: string;
|
|
37
|
-
/** The path to append to the server URL specifying the
|
|
38
|
-
|
|
37
|
+
/** The path to append to the server URL specifying the progress API endpoint to use */
|
|
38
|
+
progressPath?: string;
|
|
39
|
+
/** The path to append to the server URL specifying the progress stream API endpoint to use */
|
|
40
|
+
progressStreamPath?: string;
|
|
39
41
|
/** Whether to enable debug logs */
|
|
40
42
|
debug?: boolean;
|
|
41
43
|
/** The API version to use */
|
|
@@ -58,8 +60,10 @@ export declare class Conversation {
|
|
|
58
60
|
setConversationEndpoint(conversationEndpoint: string): this;
|
|
59
61
|
/** Sets the history endpoint where the quest is sent to, appended to server URL */
|
|
60
62
|
setHistoryEndpoint(historyEndpoint: string): this;
|
|
61
|
-
/** Sets the stream endpoint where the request is sent to, appended to server URL */
|
|
62
|
-
|
|
63
|
+
/** Sets the progress stream endpoint where the request is sent to, appended to server URL */
|
|
64
|
+
setProgressStreamEndpoint(progressStreamEndpoint: string): this;
|
|
65
|
+
/** Sets the progress endpoint where the request is sent to, appended to server URL */
|
|
66
|
+
setProgressEndpoint(progressEndpoint: string): this;
|
|
63
67
|
/** Sets the conversation ID, has to be an existing conversation ID, undefined otherwise */
|
|
64
68
|
setConvoId(convoId: string | undefined): this;
|
|
65
69
|
/** Sets the AI model used for the next interaction, e.g Claude-Sonnet, GPT-4 */
|
|
@@ -81,8 +85,10 @@ export declare class Conversation {
|
|
|
81
85
|
getConversationEndpoint(): string;
|
|
82
86
|
/** Gets the current history endpoint */
|
|
83
87
|
getHistoryEndpoint(): string;
|
|
84
|
-
/** Gets the current stream endpoint */
|
|
85
|
-
|
|
88
|
+
/** Gets the current progress stream endpoint */
|
|
89
|
+
getProgressStreamEndpoint(): string;
|
|
90
|
+
/** Gets the current progress endpoint */
|
|
91
|
+
getProgressEndpoint(): string;
|
|
86
92
|
/** Gets the current options object */
|
|
87
93
|
getModel(): string | undefined;
|
|
88
94
|
/** Gets the current location-specific instructions */
|
|
@@ -94,8 +100,10 @@ export declare class Conversation {
|
|
|
94
100
|
private handleSSE;
|
|
95
101
|
/** Fetches the conversation state from the server, including message history and metadata */
|
|
96
102
|
fetchState(): Promise<ConversationStateResponse>;
|
|
97
|
-
/** Fetches the conversation stream from the server */
|
|
98
|
-
|
|
103
|
+
/** Fetches the conversation progress stream from the server */
|
|
104
|
+
fetchProgressStream(cb: (chunk: RequestResponse) => any): EventSource;
|
|
105
|
+
/** Fetches the conversation progress from the server */
|
|
106
|
+
fetchProgress(): Promise<RequestResponse[]>;
|
|
99
107
|
/** Sends a message into the conversation */
|
|
100
108
|
send(message: string, cb: (chunk: RequestResponse) => any, options?: DialogueRequestOptions): EventSource;
|
|
101
109
|
}
|
|
@@ -21,7 +21,8 @@ class Conversation {
|
|
|
21
21
|
this.endpoints = {
|
|
22
22
|
conversation: serverUrl + (config.convoPath || config.path || config_1.CONFIG.paths.conversation[config.chatApiV || DEFAULT_CONVO_API_V].base),
|
|
23
23
|
history: serverUrl + (config.historyPath || config_1.CONFIG.paths.history.chat.v1.base),
|
|
24
|
-
|
|
24
|
+
progressStream: serverUrl + (config.progressStreamPath || config_1.CONFIG.paths.progress.v4.stream),
|
|
25
|
+
progress: serverUrl + (config.progressPath || config_1.CONFIG.paths.progress.v4.base),
|
|
25
26
|
};
|
|
26
27
|
this.apiKey = config.apiKey;
|
|
27
28
|
this.debug = config.debug || false;
|
|
@@ -45,9 +46,14 @@ class Conversation {
|
|
|
45
46
|
this.endpoints.history = historyEndpoint;
|
|
46
47
|
return this;
|
|
47
48
|
}
|
|
48
|
-
/** Sets the stream endpoint where the request is sent to, appended to server URL */
|
|
49
|
-
|
|
50
|
-
this.endpoints.
|
|
49
|
+
/** Sets the progress stream endpoint where the request is sent to, appended to server URL */
|
|
50
|
+
setProgressStreamEndpoint(progressStreamEndpoint) {
|
|
51
|
+
this.endpoints.progressStream = progressStreamEndpoint;
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
/** Sets the progress endpoint where the request is sent to, appended to server URL */
|
|
55
|
+
setProgressEndpoint(progressEndpoint) {
|
|
56
|
+
this.endpoints.progress = progressEndpoint;
|
|
51
57
|
return this;
|
|
52
58
|
}
|
|
53
59
|
/** Sets the conversation ID, has to be an existing conversation ID, undefined otherwise */
|
|
@@ -95,9 +101,13 @@ class Conversation {
|
|
|
95
101
|
getHistoryEndpoint() {
|
|
96
102
|
return this.endpoints.history;
|
|
97
103
|
}
|
|
98
|
-
/** Gets the current stream endpoint */
|
|
99
|
-
|
|
100
|
-
return this.endpoints.
|
|
104
|
+
/** Gets the current progress stream endpoint */
|
|
105
|
+
getProgressStreamEndpoint() {
|
|
106
|
+
return this.endpoints.progressStream;
|
|
107
|
+
}
|
|
108
|
+
/** Gets the current progress endpoint */
|
|
109
|
+
getProgressEndpoint() {
|
|
110
|
+
return this.endpoints.progress;
|
|
101
111
|
}
|
|
102
112
|
/** Gets the current options object */
|
|
103
113
|
getModel() {
|
|
@@ -153,13 +163,30 @@ class Conversation {
|
|
|
153
163
|
return data;
|
|
154
164
|
});
|
|
155
165
|
}
|
|
156
|
-
/** Fetches the conversation stream from the server */
|
|
157
|
-
|
|
166
|
+
/** Fetches the conversation progress stream from the server */
|
|
167
|
+
fetchProgressStream(cb) {
|
|
158
168
|
if (!this.convoId)
|
|
159
169
|
throw new Error("Conversation ID is not set");
|
|
160
|
-
const url = (0, url_formatter_1.formatURL)(this.endpoints.
|
|
170
|
+
const url = (0, url_formatter_1.formatURL)(this.endpoints.progressStream, { chatId: this.convoId }, { apiKey: this.apiKey, debug: this.debug });
|
|
161
171
|
return this.handleSSE(url, cb);
|
|
162
172
|
}
|
|
173
|
+
/** Fetches the conversation progress from the server */
|
|
174
|
+
fetchProgress() {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
if (!this.convoId)
|
|
177
|
+
throw new Error("Conversation ID is not set");
|
|
178
|
+
const url = (0, url_formatter_1.formatURL)(this.endpoints.progress, { chatId: this.convoId }, { apiKey: this.apiKey, debug: this.debug });
|
|
179
|
+
const response = yield fetch(url);
|
|
180
|
+
if (!response.ok) {
|
|
181
|
+
const errorText = yield response.text();
|
|
182
|
+
throw new Error(`Failed to fetch conversation progress: ${response.status} ${response.statusText} - ${errorText}`);
|
|
183
|
+
}
|
|
184
|
+
if (response.status === 204)
|
|
185
|
+
return []; // No content, return empty array
|
|
186
|
+
const data = yield response.json();
|
|
187
|
+
return data.events;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
163
190
|
// LIFE CYCLE
|
|
164
191
|
/** Sends a message into the conversation */
|
|
165
192
|
send(message, cb, options) {
|