@butlerbot/sdk 0.0.6-alpha.1 → 0.0.6-alpha.3

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 (44) hide show
  1. package/dist/config.d.ts +12 -0
  2. package/dist/config.js +8 -0
  3. package/dist/modules/conversation.d.ts +30 -5
  4. package/dist/modules/conversation.js +68 -21
  5. package/dist/types/conversation/index.d.ts +3 -0
  6. package/dist/types/conversation/index.js +19 -0
  7. package/dist/types/conversation/v1/conversation_v1.d.ts +7 -0
  8. package/dist/types/conversation/v1/conversation_v1.js +2 -0
  9. package/dist/types/conversation/v1/index.d.ts +1 -0
  10. package/dist/types/conversation/v1/index.js +17 -0
  11. package/dist/types/conversation/v2/aisdk_types.d.ts +431 -0
  12. package/dist/types/conversation/v2/aisdk_types.js +2 -0
  13. package/dist/types/conversation/v2/conversation_v2.d.ts +74 -0
  14. package/dist/types/conversation/v2/conversation_v2.js +2 -0
  15. package/dist/types/conversation/v2/index.d.ts +1 -0
  16. package/dist/types/conversation/v2/index.js +17 -0
  17. package/dist/types/conversation/v3/aisdk_types.d.ts +431 -0
  18. package/dist/types/conversation/v3/aisdk_types.js +2 -0
  19. package/dist/types/conversation/v3/conversation_v3.d.ts +345 -0
  20. package/dist/types/conversation/v3/conversation_v3.js +2 -0
  21. package/dist/types/conversation/v3/index.d.ts +1 -0
  22. package/dist/types/conversation/v3/index.js +17 -0
  23. package/dist/types/model.d.ts +1 -0
  24. package/dist/types/model.js +2 -0
  25. package/dist/types/response/v3/ai_response_v3.d.ts +98 -0
  26. package/dist/types/response/v3/ai_response_v3.js +2 -0
  27. package/dist/types/response/v3/ai_tools_v3.d.ts +7 -0
  28. package/dist/types/response/v3/ai_tools_v3.js +2 -0
  29. package/dist/types/response/v3/dialogue_response_v3.d.ts +29 -0
  30. package/dist/types/response/v3/dialogue_response_v3.js +2 -0
  31. package/dist/types/response/v3/index.d.ts +3 -0
  32. package/dist/types/response/v3/index.js +19 -0
  33. package/dist/types/response/v4/ai_response_v4.d.ts +22 -0
  34. package/dist/types/response/v4/ai_response_v4.js +2 -0
  35. package/dist/types/response/v4/dialogue_response_v4.d.ts +29 -0
  36. package/dist/types/response/v4/dialogue_response_v4.js +2 -0
  37. package/dist/types/response/v4/index.d.ts +2 -0
  38. package/dist/types/response/v4/index.js +18 -0
  39. package/dist/types/state/convo_state_response.d.ts +11 -0
  40. package/dist/types/state/convo_state_response.js +2 -0
  41. package/dist/types/type_registry.d.ts +2 -2
  42. package/dist/types/type_registry.js +2 -2
  43. package/dist/types/v4/ai_response_v4.d.ts +37 -49
  44. package/package.json +1 -1
package/dist/config.d.ts CHANGED
@@ -10,5 +10,17 @@ export declare const CONFIG: {
10
10
  base: string;
11
11
  };
12
12
  };
13
+ history: {
14
+ chat: {
15
+ v1: {
16
+ base: string;
17
+ };
18
+ };
19
+ chats: {
20
+ v1: {
21
+ base: string;
22
+ };
23
+ };
24
+ };
13
25
  };
14
26
  };
package/dist/config.js CHANGED
@@ -8,6 +8,14 @@ exports.CONFIG = {
8
8
  conversation: {
9
9
  v3: { base: "/api/alfred/v3/chat" },
10
10
  v4: { base: "/api/alfred/v4/chat" },
11
+ },
12
+ history: {
13
+ chat: {
14
+ v1: { base: "/api/history/chat" },
15
+ },
16
+ chats: {
17
+ v1: { base: "/convo/get/history" }
18
+ }
11
19
  }
12
20
  }
13
21
  };
@@ -1,5 +1,6 @@
1
1
  import { CONFIG } from "../config";
2
2
  import { RequestResponseV3 } from "../types/type_registry";
3
+ import { ConversationStateResponse } from "../types/state/convo_state_response";
3
4
  export type DialogueRequestParams = {
4
5
  /** Unique identifier for the chat session */
5
6
  chatId?: string;
@@ -23,12 +24,19 @@ export type ConversationOptions = {
23
24
  apiKey: string;
24
25
  /** The server URL to use */
25
26
  serverUrl?: string;
26
- /** The path to append to the server URL specifying the API endpoint to use */
27
+ /**
28
+ * The path to append to the server URL specifying the API endpoint to use (specifically for conversations)
29
+ * @deprecated use convoPath instead
30
+ */
27
31
  path?: string;
32
+ /** The path to append to the server URL specifying the conversation API endpoint to use */
33
+ convoPath?: string;
34
+ /** The path to append to the server URL specifying the history API endpoint to use */
35
+ historyPath?: string;
28
36
  /** Whether to enable debug logs */
29
37
  debug?: boolean;
30
38
  /** The API version to use */
31
- api?: APIPath;
39
+ chatApiV?: APIPath;
32
40
  };
33
41
  export type RequestResponse = RequestResponseV3;
34
42
  export declare class Conversation {
@@ -36,10 +44,17 @@ export declare class Conversation {
36
44
  apiKey: string;
37
45
  private debug;
38
46
  private options?;
39
- private endpoint;
47
+ private endpoints;
40
48
  constructor(config: ConversationOptions);
41
- /** Sets the endpoint where the request is sent to, appended to server URL */
49
+ /**
50
+ * Sets the endpoint where the request is sent to, appended to server URL
51
+ * @deprecated Use setConversationEndpoint() instead
52
+ */
42
53
  setEndpoint(endpoint: string): this;
54
+ /** Sets the conversation endpoint where the request is sent to, appended to server URL */
55
+ setConversationEndpoint(conversationEndpoint: string): this;
56
+ /** Sets the history endpoint where the quest is sent to, appended to server URL */
57
+ setHistoryEndpoint(historyEndpoint: string): this;
43
58
  /** Sets the conversation ID, has to be an existing conversation ID, undefined otherwise */
44
59
  setConvoId(convoId: string | undefined): this;
45
60
  /** Sets the AI model used for the next interaction, e.g Claude-Sonnet, GPT-4 */
@@ -52,8 +67,15 @@ export declare class Conversation {
52
67
  setPersonality(personality: string): this;
53
68
  /** Gets the current conversation ID */
54
69
  getConvoId(): string | undefined;
55
- /** Gets the current endpoint */
70
+ /**
71
+ * Gets the current endpoint
72
+ * @deprecated Use getConversationEndpoint() instead
73
+ */
56
74
  getEndpoint(): string;
75
+ /** Gets the current conversation endpoint */
76
+ getConversationEndpoint(): string;
77
+ /** Gets the current history endpoint */
78
+ getHistoryEndpoint(): string;
57
79
  /** Gets the current options object */
58
80
  getModel(): string | undefined;
59
81
  /** Gets the current location-specific instructions */
@@ -62,6 +84,9 @@ export declare class Conversation {
62
84
  getPlatform(): string | undefined;
63
85
  /** Gets the current personality configuration */
64
86
  getPersonality(): string | undefined;
87
+ formatURL(url: string, params?: Object): string;
88
+ /** Fetches the conversation state from the server, including message history and metadata */
89
+ fetchState(): Promise<ConversationStateResponse>;
65
90
  /** Sends a message into the conversation */
66
91
  send(message: string, cb: (chunk: RequestResponse) => any, options?: DialogueRequestOptions): Promise<void>;
67
92
  }
@@ -12,18 +12,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Conversation = void 0;
13
13
  const eventsource_1 = require("eventsource");
14
14
  const config_1 = require("../config");
15
- const DEFAULT_API = "v3";
15
+ const DEFAULT_CONVO_API_V = "v3";
16
16
  class Conversation {
17
17
  constructor(config) {
18
18
  this.convoId = config.convoId;
19
- this.endpoint = (config.serverUrl || config_1.CONFIG.server) + (config.path || config_1.CONFIG.paths.conversation[config.api || DEFAULT_API].base);
19
+ const serverUrl = config.serverUrl || config_1.CONFIG.server;
20
+ this.endpoints = {
21
+ conversation: serverUrl + (config.convoPath || config.path || config_1.CONFIG.paths.conversation[config.chatApiV || DEFAULT_CONVO_API_V].base),
22
+ history: serverUrl + (config.historyPath || config_1.CONFIG.paths.history.chat.v1.base),
23
+ };
20
24
  this.apiKey = config.apiKey;
21
25
  this.debug = config.debug || false;
22
26
  }
23
27
  // SETTERS
24
- /** Sets the endpoint where the request is sent to, appended to server URL */
28
+ /**
29
+ * Sets the endpoint where the request is sent to, appended to server URL
30
+ * @deprecated Use setConversationEndpoint() instead
31
+ */
25
32
  setEndpoint(endpoint) {
26
- this.endpoint = endpoint;
33
+ this.endpoints.conversation = endpoint;
34
+ return this;
35
+ }
36
+ /** Sets the conversation endpoint where the request is sent to, appended to server URL */
37
+ setConversationEndpoint(conversationEndpoint) {
38
+ this.endpoints.conversation = conversationEndpoint;
39
+ return this;
40
+ }
41
+ /** Sets the history endpoint where the quest is sent to, appended to server URL */
42
+ setHistoryEndpoint(historyEndpoint) {
43
+ this.endpoints.history = historyEndpoint;
27
44
  return this;
28
45
  }
29
46
  /** Sets the conversation ID, has to be an existing conversation ID, undefined otherwise */
@@ -56,9 +73,20 @@ class Conversation {
56
73
  getConvoId() {
57
74
  return this.convoId;
58
75
  }
59
- /** Gets the current endpoint */
76
+ /**
77
+ * Gets the current endpoint
78
+ * @deprecated Use getConversationEndpoint() instead
79
+ */
60
80
  getEndpoint() {
61
- return this.endpoint;
81
+ return this.endpoints.conversation;
82
+ }
83
+ /** Gets the current conversation endpoint */
84
+ getConversationEndpoint() {
85
+ return this.endpoints.conversation;
86
+ }
87
+ /** Gets the current history endpoint */
88
+ getHistoryEndpoint() {
89
+ return this.endpoints.history;
62
90
  }
63
91
  /** Gets the current options object */
64
92
  getModel() {
@@ -80,25 +108,44 @@ class Conversation {
80
108
  var _a;
81
109
  return (_a = this.options) === null || _a === void 0 ? void 0 : _a.personality;
82
110
  }
111
+ // HELPERS
112
+ formatURL(url, params = {}) {
113
+ const fParams = Object.assign({ api_key: this.apiKey }, params);
114
+ const paramQuery = new URLSearchParams(fParams).toString();
115
+ const fUrl = `${url}?${paramQuery}`;
116
+ if (this.debug) {
117
+ const debugUrl = new URL(fUrl);
118
+ const apiKey = debugUrl.searchParams.get('api_key');
119
+ if (apiKey) {
120
+ const obscuredKey = apiKey.length > 6 ? `${apiKey.slice(0, 3)}...${apiKey.slice(-3)}` : '***';
121
+ debugUrl.searchParams.set('api_key', obscuredKey);
122
+ }
123
+ console.log(`[Formatting URL ${debugUrl.toString()}]`);
124
+ }
125
+ return fUrl;
126
+ }
127
+ // GETTERS
128
+ /** Fetches the conversation state from the server, including message history and metadata */
129
+ fetchState() {
130
+ return __awaiter(this, void 0, void 0, function* () {
131
+ if (!this.convoId)
132
+ throw new Error("Conversation ID is not set");
133
+ const url = this.formatURL(`${this.endpoints.history}/${this.convoId}`);
134
+ const response = yield fetch(url);
135
+ if (!response.ok) {
136
+ const errorText = yield response.text();
137
+ throw new Error(`Failed to fetch conversation state: ${response.status} ${response.statusText} - ${errorText}`);
138
+ }
139
+ const data = yield response.json();
140
+ return data;
141
+ });
142
+ }
83
143
  // LIFE CYCLE
84
144
  /** Sends a message into the conversation */
85
145
  send(message, cb, options) {
86
146
  return __awaiter(this, void 0, void 0, function* () {
87
- const params = Object.assign(Object.assign({ message, api_key: this.apiKey }, this.options), options // overwrite convos for this call
88
- );
89
- if (this.convoId)
90
- params.chatId = this.convoId;
91
- const paramQuery = new URLSearchParams(params).toString();
92
- const url = `${this.endpoint}?${paramQuery}`;
93
- if (this.debug) {
94
- const debugUrl = new URL(url);
95
- const apiKey = debugUrl.searchParams.get('api_key');
96
- if (apiKey) {
97
- const obscuredKey = apiKey.length > 6 ? `${apiKey.slice(0, 3)}...${apiKey.slice(-3)}` : '***';
98
- debugUrl.searchParams.set('api_key', obscuredKey);
99
- }
100
- console.log(`[Requesting URL ${debugUrl.toString()}]`);
101
- }
147
+ const url = this.formatURL(this.endpoints.conversation, Object.assign(Object.assign({ message }, this.options), options // overwrite convos for this call
148
+ ));
102
149
  const sse = new eventsource_1.EventSource(url);
103
150
  sse.addEventListener("message", (event) => {
104
151
  const data = JSON.parse(event.data);
@@ -0,0 +1,3 @@
1
+ export * from "./v1";
2
+ export * from "./v2";
3
+ export * from "./v3";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./v1"), exports);
18
+ __exportStar(require("./v2"), exports);
19
+ __exportStar(require("./v3"), exports);
@@ -0,0 +1,7 @@
1
+ export interface ConversationV1 {
2
+ version?: "1.0";
3
+ conversationId: string;
4
+ ownerUserId: string;
5
+ /** The actual profile data */
6
+ profile: Object;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export * from "./conversation_v1";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./conversation_v1"), exports);