macrocosmos 1.2.20 → 1.2.21

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.
@@ -76,42 +76,67 @@ describe("ApexClient", () => {
76
76
  // chat id doesn't exist so check first element is an empty object
77
77
  expect(Object.keys(result.chatCompletions[0] || {}).length).toBe(0);
78
78
  }, 30000);
79
- // it("should append a chat completion", async () => {
80
- // // chat ID for testing
81
- //
82
- // const create_chat_result = await client.createChatAndCompletion({
83
- // userPrompt: "This is a test chat, how are you?",
84
- // chatType: "apex",
85
- // completionType: "basic",
86
- // title: "Test Chat",
87
- // });
88
- //
89
- // // Verify the response structure
90
- // console.log("Create chat and completion response:", create_chat_result);
91
- // expect(create_chat_result).toBeDefined();
92
- // // Get stored chat completions
93
- // const result = await client.createCompletion({
94
- // chatId: create_chat_result.parsedChat?.id ?? "",
95
- // userPrompt: "This is a test completion, how are you?",
96
- // completionType: "basic",
97
- // });
98
- //
99
- // // Verify the response structure
100
- // console.log("Create completion response:", result);
101
- // expect(result).toBeDefined();
102
- //
103
- // // Check ParsedCompletion
104
- // expect(result.parsedCompletion).toBeDefined();
105
- // expect(result.parsedCompletion!.id).toBeDefined();
106
- // expect(result.parsedCompletion!.chatId).toBe(
107
- // create_chat_result.parsedChat!.id,
108
- // );
109
- // expect(result.parsedCompletion!.completionType).toBe("basic");
110
- // expect(result.parsedCompletion!.userPromptText).toBe(
111
- // "This is a test completion, how are you?",
112
- // );
113
- //
114
- // }, 30000);
79
+ it("should append a chat completion", async () => {
80
+ // create a test chat
81
+ const create_chat_result = await client.createChatAndCompletion({
82
+ userPrompt: "This is a test chat, how are you?",
83
+ chatType: "apex",
84
+ completionType: "basic",
85
+ title: "Test Chat",
86
+ });
87
+ // Verify a chat id exists (i.e., a chat was created)
88
+ console.log("Create chat response:", create_chat_result);
89
+ expect(create_chat_result).toBeDefined();
90
+ expect(create_chat_result.parsedChat?.id).toBeDefined();
91
+ // Create Completion under this chat
92
+ const result = await client.createCompletion({
93
+ chatId: create_chat_result.parsedChat?.id ?? "",
94
+ userPrompt: "This is a test completion, how are you?",
95
+ completionType: "basic",
96
+ });
97
+ // Verify the response structure
98
+ console.log("Create completion response:", result);
99
+ expect(result).toBeDefined();
100
+ // Check ParsedCompletion
101
+ expect(result.parsedCompletion).toBeDefined();
102
+ expect(result.parsedCompletion.id).toBeDefined();
103
+ expect(result.parsedCompletion.chatId).toBe(create_chat_result.parsedChat.id);
104
+ // make sure the completion type is basic
105
+ expect(result.parsedCompletion.completionType).toBe("basic");
106
+ // make sure the completion text is what we sent
107
+ expect(result.parsedCompletion.userPromptText).toBe("This is a test completion, how are you?");
108
+ // Delete test chat
109
+ const delete_chat_result = await client.deleteChats({
110
+ chatIds: [create_chat_result.parsedChat?.id ?? ""],
111
+ });
112
+ expect(delete_chat_result).toBeDefined();
113
+ expect(delete_chat_result.success).toBeTruthy();
114
+ }, 30000);
115
+ it("should delete a chat", async () => {
116
+ // chat ID for testing
117
+ const create_chat_result = await client.createChatAndCompletion({
118
+ userPrompt: "This is a test chat, how are you?",
119
+ chatType: "apex",
120
+ completionType: "basic",
121
+ title: "Test Chat",
122
+ });
123
+ // Verify the response structure
124
+ console.log("Create chat response:", create_chat_result);
125
+ expect(create_chat_result).toBeDefined();
126
+ // Delete test chat
127
+ const delete_chat_result = await client.deleteChats({
128
+ chatIds: [create_chat_result.parsedChat?.id ?? ""],
129
+ });
130
+ expect(delete_chat_result).toBeDefined();
131
+ expect(delete_chat_result.success).toBeTruthy();
132
+ const get_chat_sessions_result = await client.getChatSessions();
133
+ // Verify the response structure
134
+ console.log("Stored chats:", get_chat_sessions_result);
135
+ expect(get_chat_sessions_result).toBeDefined();
136
+ // should be an empty array as we just deleted the chat
137
+ expect(Array.isArray(get_chat_sessions_result.chatSessions)).toBe(true);
138
+ expect(get_chat_sessions_result.chatSessions.some(session => session.id === create_chat_result.parsedChat?.id)).toBe(false);
139
+ }, 30000);
115
140
  // Deep Researcher Tests
116
141
  it("should create a deep research job", async () => {
117
142
  // Create test parameters
@@ -153,55 +178,55 @@ describe("ApexClient", () => {
153
178
  // Log response for debugging
154
179
  console.log("Get Job Results Response:", response);
155
180
  }, 60000); // Longer timeout for this test as it involves multiple API calls
156
- // TODO: Uncomment this when delete chat is available, so we can remove all test chats first
157
- // it("should retrieve a user's completions based on the search term", async () => {
158
- // const searchTerm = "France?";
159
- // // Get stored chat completions
160
- // const result = await client.searchChatIdsByPromptAndCompletionText({
161
- // searchTerm: searchTerm,
162
- // });
163
- // // Verify the response structure
164
- // console.log("Stored chats:", result);
165
- // expect(result).toBeDefined();
166
- // expect(Array.isArray(result.chatIds)).toBe(true);
167
- // // chat id doesn't exist so check first element is an empty object
168
- // expect(Object.keys(result.chatIds[0] || {}).length).toBe(0);
169
- // }, 30000);
170
- // it("should create a chat and completion for a user", async () => {
171
- // const result = await client.createChatAndCompletion({
172
- // userPrompt: "This is a test chat, how are you?",
173
- // chatType: "apex",
174
- // completionType: "basic",
175
- // title: "Test Chat",
176
- // });
177
- // // Verify the response structure
178
- // console.log("Create chat and completion response:", result);
179
- // expect(result).toBeDefined();
180
- // // Check ParsedChat
181
- // expect(result.parsedChat).toBeDefined();
182
- // expect(result.parsedChat!.id).toBeDefined();
183
- // expect(result.parsedChat!.title).toBe("Test Chat");
184
- // expect(result.parsedChat!.chatType).toBe("apex");
185
- // expect(result.parsedChat!.createdAt).toBeDefined();
186
- // // Check ParsedCompletion
187
- // expect(result.parsedCompletion).toBeDefined();
188
- // expect(result.parsedCompletion!.id).toBeDefined();
189
- // expect(result.parsedCompletion!.chatId).toBe(result.parsedChat!.id);
190
- // expect(result.parsedCompletion!.completionType).toBe("basic");
191
- // expect(result.parsedCompletion!.userPromptText).toBe(
192
- // "This is a test chat, how are you?",
193
- // );
194
- // expect(result.parsedCompletion!.completionText).toBeDefined();
195
- // expect(result.parsedCompletion!.createdAt).toBeDefined();
196
- // }, 30000);
197
- // it("should retrieve a user's stored chats", async () => {
198
- // // Get stored chat completions
199
- // const result = await client.getChatSessions();
200
- // // Verify the response structure
201
- // console.log("Stored chats:", result);
202
- // expect(result).toBeDefined();
203
- // expect(Array.isArray(result.chatSessions)).toBe(true);
204
- // // chat id doesn't exist so check first element is an empty object
205
- // expect(Object.keys(result.chatSessions[0] || {}).length).toBe(0);
206
- // }, 30000);
181
+ it("should retrieve a user's completions based on the search term", async () => {
182
+ const searchTerm = "France?";
183
+ // Get stored chat completions
184
+ const result = await client.searchChatIdsByPromptAndCompletionText({
185
+ searchTerm: searchTerm,
186
+ });
187
+ // Verify the response structure
188
+ console.log("Stored chats:", result);
189
+ expect(result).toBeDefined();
190
+ expect(Array.isArray(result.chatIds)).toBe(true);
191
+ // chat id doesn't exist so check first element is an empty object
192
+ expect(Object.keys(result.chatIds[0] || {}).length).toBe(0);
193
+ }, 30000);
194
+ it("should create a chat and completion for a user", async () => {
195
+ const result = await client.createChatAndCompletion({
196
+ userPrompt: "This is a test chat, how are you?",
197
+ chatType: "apex",
198
+ completionType: "basic",
199
+ title: "Test Chat",
200
+ });
201
+ // Verify the response structure
202
+ console.log("Create chat and completion response:", result);
203
+ expect(result).toBeDefined();
204
+ // Check ParsedChat
205
+ expect(result.parsedChat).toBeDefined();
206
+ expect(result.parsedChat.id).toBeDefined();
207
+ expect(result.parsedChat.title).toBe("Test Chat");
208
+ expect(result.parsedChat.chatType).toBe("apex");
209
+ expect(result.parsedChat.createdAt).toBeDefined();
210
+ // Check ParsedCompletion
211
+ expect(result.parsedCompletion).toBeDefined();
212
+ expect(result.parsedCompletion.id).toBeDefined();
213
+ expect(result.parsedCompletion.chatId).toBe(result.parsedChat.id);
214
+ expect(result.parsedCompletion.completionType).toBe("basic");
215
+ expect(result.parsedCompletion.userPromptText).toBe("This is a test chat, how are you?");
216
+ expect(result.parsedCompletion.completionText).toBeDefined();
217
+ expect(result.parsedCompletion.createdAt).toBeDefined();
218
+ // Delete test chat
219
+ const delete_chat_result = await client.deleteChats({
220
+ chatIds: [result.parsedChat?.id ?? ""],
221
+ });
222
+ expect(delete_chat_result.success).toBeTruthy();
223
+ }, 30000);
224
+ it("should retrieve a user's stored chats", async () => {
225
+ // Get stored chat completions
226
+ const result = await client.getChatSessions();
227
+ // Verify the response structure
228
+ console.log("Stored chats:", result);
229
+ expect(result).toBeDefined();
230
+ expect(Array.isArray(result.chatSessions)).toBe(true);
231
+ }, 30000);
207
232
  });
@@ -1,4 +1,4 @@
1
- import { ApexServiceClient, ChatCompletionRequest as GeneratedChatCompletionRequest, ChatCompletionResponse, ChatCompletionChunkResponse, WebRetrievalRequest as GeneratedWebRetrievalRequest, WebRetrievalResponse, ChatMessage, SubmitDeepResearcherJobResponse, GetDeepResearcherJobRequest, GetDeepResearcherJobResponse, GetStoredChatCompletionsRequest, GetStoredChatCompletionsResponse, GetChatSessionsResponse, SearchChatIdsByPromptAndCompletionTextRequest, SearchChatIdsByPromptAndCompletionTextResponse, CreateChatAndCompletionRequest, CreateChatAndCompletionResponse, CreateCompletionRequest, CreateCompletionResponse } from "../../generated/apex/v1/apex";
1
+ import { ApexServiceClient, ChatCompletionRequest as GeneratedChatCompletionRequest, ChatCompletionResponse, ChatCompletionChunkResponse, WebRetrievalRequest as GeneratedWebRetrievalRequest, WebRetrievalResponse, ChatMessage, SubmitDeepResearcherJobResponse, GetDeepResearcherJobRequest, GetDeepResearcherJobResponse, GetStoredChatCompletionsRequest, GetStoredChatCompletionsResponse, GetChatSessionsResponse, SearchChatIdsByPromptAndCompletionTextRequest, SearchChatIdsByPromptAndCompletionTextResponse, CreateChatAndCompletionRequest, CreateChatAndCompletionResponse, CreateCompletionRequest, CreateCompletionResponse, DeleteChatsRequest, DeleteChatsResponse } from "../../generated/apex/v1/apex";
2
2
  import * as grpc from "@grpc/grpc-js";
3
3
  import { BaseClient, BaseClientOptions } from "../BaseClient";
4
4
  import { ApexStream } from "./Stream";
@@ -81,4 +81,8 @@ export declare class ApexClient extends BaseClient {
81
81
  * Create completion for a chat
82
82
  */
83
83
  createCompletion: (params: CreateCompletionRequest) => Promise<CreateCompletionResponse>;
84
+ /**
85
+ * Delete a chat given its id
86
+ */
87
+ deleteChats: (params: DeleteChatsRequest) => Promise<DeleteChatsResponse>;
84
88
  }
@@ -216,6 +216,21 @@ class ApexClient extends BaseClient_1.BaseClient {
216
216
  });
217
217
  });
218
218
  };
219
+ /**
220
+ * Delete a chat given its id
221
+ */
222
+ this.deleteChats = async (params) => {
223
+ const client = this.createGrpcClient();
224
+ return new Promise((resolve, reject) => {
225
+ client.deleteChats(params, (error, response) => {
226
+ if (error) {
227
+ reject(error);
228
+ return;
229
+ }
230
+ resolve(response);
231
+ });
232
+ });
233
+ };
219
234
  this.defaultTimeout = options.timeout || 60;
220
235
  this._grpcClient = grpcClient;
221
236
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "1.2.20";
1
+ export declare const VERSION = "1.2.21";
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = "1.2.20";
4
+ exports.VERSION = "1.2.21";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "macrocosmos",
3
- "version": "1.2.20",
3
+ "version": "1.2.21",
4
4
  "description": "TypeScript SDK package for Macrocosmos",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",