macrocosmos 1.4.2 → 2.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.
@@ -2,7 +2,7 @@
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
4
  // protoc-gen-ts_proto v2.7.0
5
- // protoc v6.32.1
5
+ // protoc v6.33.0
6
6
  // source: logger/v1/logger.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.LoggerServiceClient = exports.LoggerServiceService = exports.StoreRecordBatchRequest = exports.Record = exports.CreateRunRequest = exports.Ack = exports.protobufPackage = void 0;
@@ -2,7 +2,7 @@
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
4
  // protoc-gen-ts_proto v2.7.0
5
- // protoc v6.32.1
5
+ // protoc v6.33.0
6
6
  // source: sn13/v1/sn13_validator.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.Sn13ServiceClient = exports.Sn13ServiceService = exports.OnDemandDataResponse = exports.OnDemandDataRequest = exports.ValidateRedditTopicResponse = exports.ValidateRedditTopicRequest = exports.ListTopicsResponse = exports.ListTopicsResponseDetail = exports.ListTopicsRequest = exports.protobufPackage = void 0;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from "./constants";
2
- export * from "./lib/apex";
3
2
  export * from "./lib/gravity";
4
3
  export * from "./lib/billing";
5
4
  export * from "./lib/sn13";
package/dist/index.js CHANGED
@@ -16,8 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  // Export constants
18
18
  __exportStar(require("./constants"), exports);
19
- // Export apex modules
20
- __exportStar(require("./lib/apex"), exports);
21
19
  // Export gravity modules
22
20
  __exportStar(require("./lib/gravity"), exports);
23
21
  // Export billing modules
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "1.4.2";
1
+ export declare const VERSION = "2.0.0";
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.4.2";
4
+ exports.VERSION = "2.0.0";
package/package.json CHANGED
@@ -1,14 +1,18 @@
1
1
  {
2
2
  "name": "macrocosmos",
3
- "version": "1.4.2",
3
+ "version": "2.0.0",
4
4
  "description": "TypeScript SDK package for Macrocosmos",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
- "files": ["dist/", "README.md", "LICENSE"],
7
+ "files": [
8
+ "dist/",
9
+ "README.md",
10
+ "LICENSE"
11
+ ],
8
12
  "scripts": {
9
13
  "clean": "rimraf dist",
10
14
  "gen:version": "node scripts/generate-version.js",
11
- "build": "npm run clean && npm run gen:version && npm run gen:proto && tsc && cp README.md dist/ && cp LICENSE dist/",
15
+ "build": "npm run clean && npm run gen:version && npm run proto:gen && tsc && cp README.md dist/ && cp LICENSE dist/",
12
16
  "pack": "npm pack && tar -tf macrocosmos-$(node -p \"require('./package.json').version\").tgz && open macrocosmos-$(node -p \"require('./package.json').version\").tgz",
13
17
  "pack:rm": "rm macrocosmos-$(node -p \"require('./package.json').version\").tgz && rm -rf package",
14
18
  "ts-check": "tsc --noEmit",
@@ -18,7 +22,8 @@
18
22
  "lint:fix": "eslint . --ext .ts --fix",
19
23
  "format:check": "prettier --check \"src/**/*.{ts,js,json,md}\"",
20
24
  "format:write": "prettier --write \"src/**/*.{ts,js,json,md}\"",
21
- "gen:proto": "npx protoc --plugin=protoc-gen-ts_proto=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=./src/generated --ts_proto_opt=outputServices=grpc-js,useOptionals=messages,useExactTypes=false,esModuleInterop=true,forceLong=number -I ./protos $(find ./protos -name \"*.proto\") && prettier --write \"src/generated/**/*.{ts,js,json,md}\" ",
25
+ "proto:pull": "git subtree pull --prefix=protos git@github.com:macrocosm-os/macrocosmos-protos.git main --squash",
26
+ "proto:gen": "npx protoc --plugin=protoc-gen-ts_proto=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=./src/generated --ts_proto_opt=outputServices=grpc-js,useOptionals=messages,useExactTypes=false,esModuleInterop=true,forceLong=number -I ./protos $(find ./protos -name \"*.proto\") && prettier --write \"src/generated/**/*.{ts,js,json,md}\" ",
22
27
  "example:sn13:list-topics": "ts-node src/__examples__/sn13/list-topics.ts",
23
28
  "prepare": "husky"
24
29
  },
@@ -1 +0,0 @@
1
- export {};
@@ -1,324 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const macrocosmos_1 = require("macrocosmos");
4
- describe("ApexClient", () => {
5
- const API_KEY = process.env.MACROCOSMOS_API_KEY;
6
- if (!API_KEY) {
7
- throw new Error("MACROCOSMOS_API_KEY environment variable is required");
8
- }
9
- const messages = [
10
- {
11
- role: "user",
12
- content: "What is the capital of France?",
13
- },
14
- ];
15
- const deepResearchMessages = [
16
- {
17
- role: "user",
18
- content: `Can you propose a mechanism by which a decentralized network
19
- of AI agents could achieve provable alignment on abstract ethical principles
20
- without relying on human-defined ontologies or centralized arbitration?`,
21
- },
22
- ];
23
- const samplingParameters = {
24
- temperature: 0.7,
25
- topP: 0.9,
26
- maxNewTokens: 100,
27
- doSample: true,
28
- };
29
- const createChatAndCompletionParams = {
30
- userPrompt: "This is a test chat, how are you?",
31
- chatType: "apex",
32
- completionType: "basic",
33
- title: "Test Chat",
34
- };
35
- let client;
36
- beforeEach(() => {
37
- client = new macrocosmos_1.ApexClient({
38
- apiKey: API_KEY,
39
- appName: "apex-client.test.ts",
40
- });
41
- });
42
- it.skip("should make a streaming chat completion call", async () => {
43
- // Create streaming completion
44
- const result = await client.chat.completions.create({
45
- messages,
46
- stream: true,
47
- samplingParameters,
48
- });
49
- // Handle streaming response
50
- let fullResponse = "";
51
- const stream = result;
52
- for await (const chunk of stream) {
53
- // We know the interface matches the proto definition
54
- const content = chunk.choices?.[0]?.delta?.content || "";
55
- fullResponse += content;
56
- console.log("Received chunk:", content);
57
- }
58
- console.log("Full response:", fullResponse);
59
- expect(fullResponse).toBeTruthy();
60
- expect(fullResponse.toLowerCase()).toContain("paris");
61
- }, 30000); // Increase timeout to 30 seconds for streaming
62
- // TODO: This test is skipped due to a server-side issue with the non-streaming ChatCompletion endpoint.
63
- // The server returns "failed to parse response" error, suggesting the response format doesn't match
64
- // the expected ChatCompletionResponse protobuf format. The streaming endpoint works fine.
65
- it.skip("should make a non-streaming chat completion call", async () => {
66
- // Create non-streaming completion
67
- const response = await client.chat.completions.create({
68
- messages,
69
- samplingParameters,
70
- });
71
- console.log("Response:", response.choices?.[0]?.message?.content);
72
- expect(response.choices?.[0]?.message?.content).toBeTruthy();
73
- expect(response.choices?.[0]?.message?.content?.toLowerCase()).toContain("paris");
74
- }, 30000); // Increase timeout to 30 seconds
75
- it("should retrieve stored chat completions", async () => {
76
- // chat ID for testing
77
- const chatId = "test-chat-id";
78
- // Get stored chat completions
79
- const result = await client.getStoredChatCompletions({ chatId });
80
- // Verify the response structure
81
- console.log("Stored chat completions:", result);
82
- expect(result).toBeDefined();
83
- expect(Array.isArray(result.chatCompletions)).toBe(true);
84
- // chat id doesn't exist so check first element is an empty object
85
- expect(Object.keys(result.chatCompletions[0] || {}).length).toBe(0);
86
- }, 30000);
87
- it("should append a chat completion", async () => {
88
- // create a test chat
89
- const create_chat_result = await client.createChatAndCompletion(createChatAndCompletionParams);
90
- // Verify a chat id exists (i.e., a chat was created)
91
- console.log("Create chat response:", create_chat_result);
92
- expect(create_chat_result).toBeDefined();
93
- expect(create_chat_result.parsedChat?.id).toBeDefined();
94
- // Create Completion under this chat
95
- const result = await client.createCompletion({
96
- chatId: create_chat_result.parsedChat?.id ?? "",
97
- userPrompt: "This is a test completion, how are you?",
98
- completionType: "basic",
99
- });
100
- // Verify the response structure
101
- console.log("Create completion response:", result);
102
- expect(result).toBeDefined();
103
- // Check ParsedCompletion
104
- expect(result.parsedCompletion).toBeDefined();
105
- expect(result.parsedCompletion.id).toBeDefined();
106
- expect(result.parsedCompletion.chatId).toBe(create_chat_result.parsedChat.id);
107
- // make sure the completion type is basic
108
- expect(result.parsedCompletion.completionType).toBe("basic");
109
- // make sure the completion text is what we sent
110
- expect(result.parsedCompletion.userPromptText).toBe("This is a test completion, how are you?");
111
- // Delete test chat
112
- const delete_chat_result = await client.deleteChats({
113
- chatIds: [create_chat_result.parsedChat?.id ?? ""],
114
- });
115
- expect(delete_chat_result).toBeDefined();
116
- expect(delete_chat_result.success).toBeTruthy();
117
- }, 30000);
118
- it("should delete a chat", async () => {
119
- // chat ID for testing
120
- const create_chat_result = await client.createChatAndCompletion(createChatAndCompletionParams);
121
- // Verify the response structure
122
- console.log("Create chat response:", create_chat_result);
123
- expect(create_chat_result).toBeDefined();
124
- // Delete test chat
125
- const delete_chat_result = await client.deleteChats({
126
- chatIds: [create_chat_result.parsedChat?.id ?? ""],
127
- });
128
- expect(delete_chat_result).toBeDefined();
129
- expect(delete_chat_result.success).toBeTruthy();
130
- const get_chat_sessions_result = await client.getChatSessions({
131
- chatType: "apex",
132
- });
133
- // Verify the response structure
134
- console.log("Stored chats:", get_chat_sessions_result);
135
- expect(get_chat_sessions_result).toBeDefined();
136
- // make sure the chat does not exist in the chats retrieved
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);
140
- it("should retrieve a completion", async () => {
141
- // chat ID for testing
142
- const create_chat_result = await client.createChatAndCompletion(createChatAndCompletionParams);
143
- // Verify create chat was successful
144
- console.log("Create chat response:", create_chat_result);
145
- expect(create_chat_result).toBeDefined();
146
- // Get the completion created in the chat
147
- const get_chat_completion_result = await client.getChatCompletion({
148
- completionId: create_chat_result.parsedCompletion?.id ?? "",
149
- });
150
- // Make sure the retrieved completion matches the created one
151
- expect(get_chat_completion_result).toBeDefined();
152
- expect(get_chat_completion_result.id).toBe(create_chat_result.parsedCompletion?.id);
153
- expect(get_chat_completion_result.chatId).toBe(create_chat_result.parsedChat?.id);
154
- expect(get_chat_completion_result.completionType).toBe(create_chat_result.parsedCompletion?.completionType);
155
- expect(get_chat_completion_result.createdAt?.toISOString()).toBe(create_chat_result.parsedCompletion?.createdAt?.toISOString());
156
- expect(get_chat_completion_result.userPromptText).toBe(create_chat_result.parsedCompletion?.userPromptText);
157
- expect(get_chat_completion_result.metadata).toStrictEqual(create_chat_result.parsedCompletion?.metadata);
158
- const delete_chat_result = await client.deleteChats({
159
- chatIds: [create_chat_result.parsedChat?.id ?? ""],
160
- });
161
- expect(delete_chat_result.success).toBeTruthy();
162
- }, 30000);
163
- it("should delete a completion", async () => {
164
- // chat ID for testing
165
- const create_completion_result = await client.createChatAndCompletion(createChatAndCompletionParams);
166
- console.log("Create completion response:", create_completion_result);
167
- expect(create_completion_result).toBeDefined();
168
- // Delete test completion
169
- const delete_completion_result = await client.deleteCompletions({
170
- completionIds: [create_completion_result.parsedCompletion?.id ?? ""],
171
- });
172
- expect(delete_completion_result).toBeDefined();
173
- expect(delete_completion_result.success).toBeTruthy();
174
- const get_chat_completions_result = await client.getStoredChatCompletions({
175
- chatId: create_completion_result.parsedChat?.id ?? "",
176
- });
177
- console.log("Stored completions:", get_chat_completions_result);
178
- expect(get_chat_completions_result).toBeDefined();
179
- // make sure the completion does not exist in the chats retrieved
180
- expect(get_chat_completions_result.chatCompletions.some(completion => completion.id === create_completion_result.parsedCompletion?.id)).toBe(false);
181
- // Now delete test chat
182
- const delete_chat_result = await client.deleteChats({
183
- chatIds: [create_completion_result.parsedChat?.id ?? ""],
184
- });
185
- expect(delete_chat_result.success).toBeTruthy();
186
- }, 30000);
187
- // Deep Researcher Tests - skipped due to failure, Deep Researcher has also been retired
188
- it.skip("should create a deep research job", async () => {
189
- // Create test parameters
190
- const params = {
191
- messages: deepResearchMessages,
192
- model: "Default",
193
- samplingParameters: samplingParameters,
194
- seed: 42,
195
- uids: [1, 2, 3],
196
- };
197
- // Submit the job
198
- const response = await client.submitDeepResearcherJob(params);
199
- // Verify response structure
200
- expect(response).toBeDefined();
201
- expect(typeof response.jobId).toBe("string");
202
- expect(typeof response.status).toBe("string");
203
- expect(typeof response.createdAt).toBe("string");
204
- expect(typeof response.updatedAt).toBe("string");
205
- // Log response for debugging
206
- console.log("Create Job Response:", response);
207
- }, 30000);
208
- it.skip("should get deep researcher job results", async () => {
209
- // First create a job. Use simple inputs as job creation is tested in the previous test.
210
- const createParams = {
211
- messages: deepResearchMessages,
212
- };
213
- const createResponse = await client.submitDeepResearcherJob(createParams);
214
- const jobId = createResponse.jobId;
215
- // Then get the results
216
- const response = await client.getDeepResearcherJob({ jobId: jobId });
217
- // Verify response structure
218
- expect(response).toBeDefined();
219
- expect(response.jobId).toBe(jobId); // Job ID should match the one from the create response
220
- expect(typeof response.status).toBe("string");
221
- expect(typeof response.jobId).toBe("string");
222
- expect(typeof response.createdAt).toBe("string");
223
- expect(typeof response.updatedAt).toBe("string");
224
- expect(Array.isArray(response.result)).toBe(true);
225
- // Log response for debugging
226
- console.log("Get Job Results Response:", response);
227
- }, 60000); // Longer timeout for this test as it involves multiple API calls
228
- it("should retrieve a user's completions based on the search term", async () => {
229
- const searchTerm = "France?";
230
- // Get stored chat completions
231
- const result = await client.searchChatIdsByPromptAndCompletionText({
232
- searchTerm: searchTerm,
233
- });
234
- // Verify the response structure
235
- console.log("Stored chats:", result);
236
- expect(result).toBeDefined();
237
- expect(Array.isArray(result.chatIds)).toBe(true);
238
- // chat id doesn't exist so check first element is an empty object
239
- expect(Object.keys(result.chatIds[0] || {}).length).toBe(0);
240
- }, 30000);
241
- it("should create a chat and completion for a user", async () => {
242
- const result = await client.createChatAndCompletion(createChatAndCompletionParams);
243
- // Verify the response structure
244
- console.log("Create chat and completion response:", result);
245
- expect(result).toBeDefined();
246
- // Check ParsedChat
247
- expect(result.parsedChat).toBeDefined();
248
- expect(result.parsedChat.id).toBeDefined();
249
- expect(result.parsedChat.title).toBe("Test Chat");
250
- expect(result.parsedChat.chatType).toBe("apex");
251
- expect(result.parsedChat.createdAt).toBeDefined();
252
- // Check ParsedCompletion
253
- expect(result.parsedCompletion).toBeDefined();
254
- expect(result.parsedCompletion.id).toBeDefined();
255
- expect(result.parsedCompletion.chatId).toBe(result.parsedChat.id);
256
- expect(result.parsedCompletion.completionType).toBe("basic");
257
- expect(result.parsedCompletion.userPromptText).toBe("This is a test chat, how are you?");
258
- expect(result.parsedCompletion.completionText).toBeDefined();
259
- expect(result.parsedCompletion.createdAt).toBeDefined();
260
- // Delete test chat
261
- const delete_chat_result = await client.deleteChats({
262
- chatIds: [result.parsedChat?.id ?? ""],
263
- });
264
- expect(delete_chat_result.success).toBeTruthy();
265
- }, 30000);
266
- it("should retrieve a user's stored chats", async () => {
267
- // Get stored chat completions
268
- const result = await client.getChatSessions({
269
- chatType: "apex",
270
- });
271
- // Verify the response structure
272
- console.log("Stored chats:", result);
273
- expect(result).toBeDefined();
274
- expect(Array.isArray(result.chatSessions)).toBe(true);
275
- }, 30000);
276
- it("should update chat attribute", async () => {
277
- // chat ID for testing
278
- const create_chat_result = await client.createChatAndCompletion(createChatAndCompletionParams);
279
- // Verify the response structure
280
- console.log("Create chat response:", create_chat_result);
281
- expect(create_chat_result).toBeDefined();
282
- const update_chat_attributes = await client.updateChatAttributes({
283
- chatId: create_chat_result.parsedChat?.id ?? "",
284
- attributes: {
285
- title: "Updated Test Chat",
286
- chat_type: "gravity",
287
- },
288
- });
289
- expect(update_chat_attributes.chat?.title).toBe("Updated Test Chat");
290
- expect(update_chat_attributes.chat?.chatType).toBe("gravity");
291
- // Delete test chat
292
- const delete_chat_result = await client.deleteChats({
293
- chatIds: [create_chat_result.parsedChat?.id ?? ""],
294
- });
295
- expect(delete_chat_result.success).toBeTruthy();
296
- }, 30000);
297
- it("should update completion attribute", async () => {
298
- // chat ID for testing
299
- const create_chat_result = await client.createChatAndCompletion(createChatAndCompletionParams);
300
- // Verify chat was created
301
- console.log("Create chat and completion response:", create_chat_result);
302
- expect(create_chat_result).toBeDefined();
303
- const update_completion_attributes = await client.updateCompletionAttributes({
304
- completionId: create_chat_result.parsedCompletion?.id ?? "",
305
- completionText: "Updated completion text",
306
- userPromptText: "Updated user prompt text",
307
- metadata: {
308
- fancy_metadata_key: "fancy_metadata_value",
309
- },
310
- });
311
- expect(update_completion_attributes.completion?.completionText).toBe("Updated completion text");
312
- expect(update_completion_attributes.completion?.userPromptText).toBe("Updated user prompt text");
313
- expect(update_completion_attributes.completion?.metadata).toBeDefined();
314
- expect(typeof update_completion_attributes.completion?.metadata).toBe("object");
315
- expect(Object.keys(update_completion_attributes.completion?.metadata || {})
316
- .length).toBe(1);
317
- expect(update_completion_attributes.completion?.metadata?.fancy_metadata_key).toBe("fancy_metadata_value");
318
- // Delete the test chat. This also deletes the completion.
319
- const delete_chat_result = await client.deleteChats({
320
- chatIds: [create_chat_result.parsedChat?.id ?? ""],
321
- });
322
- expect(delete_chat_result.success).toBeTruthy();
323
- }, 30000);
324
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const macrocosmos_1 = require("macrocosmos");
4
- describe("ApexClient WebRetrieval", () => {
5
- const API_KEY = process.env.MACROCOSMOS_API_KEY;
6
- if (!API_KEY) {
7
- throw new Error("MACROCOSMOS_API_KEY environment variable is required");
8
- }
9
- it.skip("should make a web retrieval request", async () => {
10
- // Create ApexClient
11
- const client = new macrocosmos_1.ApexClient({
12
- apiKey: API_KEY,
13
- appName: "apex-client-web-search.test.ts",
14
- });
15
- // Create web retrieval request
16
- const request = {
17
- searchQuery: "What is Bittensor?",
18
- nResults: 5,
19
- maxResponseTime: 10000, // 10 seconds
20
- };
21
- // Make the web retrieval call
22
- const response = await client.webRetrieval(request);
23
- // Validate response
24
- expect(response).toBeTruthy();
25
- expect(response.results).toBeDefined();
26
- expect(Array.isArray(response.results)).toBe(true);
27
- // Check if we have results
28
- if (response.results && response.results.length > 0) {
29
- console.log(`Received ${response.results.length} search results`);
30
- // Log the first result
31
- const firstResult = response.results[0];
32
- console.log("First result URL:", firstResult.url);
33
- console.log("First result content snippet:", firstResult.content?.substring(0, 100) + "...");
34
- }
35
- // Expect to have at least one result
36
- expect(response.results?.length).toBeGreaterThan(0);
37
- }, 45000); // Increase timeout to 45 seconds
38
- });