macrocosmos 1.2.12 → 1.2.13

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/README.md CHANGED
@@ -15,7 +15,7 @@ npm install macrocosmos
15
15
  The Apex client provides an interface for accessing the Apex API for chat completions and web search.
16
16
 
17
17
  ```typescript
18
- import { ApexClient } from 'macrocosmos';
18
+ import { ApexClient, DeepResearch } from 'macrocosmos';
19
19
 
20
20
  // Initialize the client
21
21
  const client = new ApexClient({ apiKey: 'your-api-key' });
@@ -33,6 +33,24 @@ const response = await client.chat.completions.create({
33
33
  const webResults = await client.webRetrieval({
34
34
  query: 'latest news about AI'
35
35
  });
36
+
37
+ // Deep Researcher
38
+
39
+ // Create DeepResearch instance
40
+ const deepResearch = new DeepResearch(client);
41
+
42
+ // Submit a deep research job
43
+ const submittedResponse = await deepResearch.createJob({
44
+ messages: [
45
+ { role: "user",
46
+ content: `Can you propose a mechanism by which a decentralized network
47
+ of AI agents could achieve provable alignment on abstract ethical principles
48
+ without relying on human-defined ontologies or centralized arbitration?`},
49
+ ],
50
+ });
51
+
52
+ // Get the results of a deep research job
53
+ const polledResponse = await deepResearch.getJobResults(submittedResponse.jobId);
36
54
  ```
37
55
 
38
56
  ### Gravity Client
package/dist/README.md CHANGED
@@ -15,7 +15,7 @@ npm install macrocosmos
15
15
  The Apex client provides an interface for accessing the Apex API for chat completions and web search.
16
16
 
17
17
  ```typescript
18
- import { ApexClient } from 'macrocosmos';
18
+ import { ApexClient, DeepResearch } from 'macrocosmos';
19
19
 
20
20
  // Initialize the client
21
21
  const client = new ApexClient({ apiKey: 'your-api-key' });
@@ -33,6 +33,24 @@ const response = await client.chat.completions.create({
33
33
  const webResults = await client.webRetrieval({
34
34
  query: 'latest news about AI'
35
35
  });
36
+
37
+ // Deep Researcher
38
+
39
+ // Create DeepResearch instance
40
+ const deepResearch = new DeepResearch(client);
41
+
42
+ // Submit a deep research job
43
+ const submittedResponse = await deepResearch.createJob({
44
+ messages: [
45
+ { role: "user",
46
+ content: `Can you propose a mechanism by which a decentralized network
47
+ of AI agents could achieve provable alignment on abstract ethical principles
48
+ without relying on human-defined ontologies or centralized arbitration?`},
49
+ ],
50
+ });
51
+
52
+ // Get the results of a deep research job
53
+ const polledResponse = await deepResearch.getJobResults(submittedResponse.jobId);
36
54
  ```
37
55
 
38
56
  ### Gravity Client
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Client_1 = require("../../lib/apex/Client");
4
+ const DeepResearch_1 = require("../../lib/apex/DeepResearch");
5
+ describe("DeepResearch", () => {
6
+ const API_KEY = process.env.MACROCOSMOS_API_KEY;
7
+ if (!API_KEY) {
8
+ throw new Error("MACROCOSMOS_API_KEY environment variable is required");
9
+ }
10
+ it("should create a deep research job", async () => {
11
+ // Create ApexClient
12
+ const client = new Client_1.ApexClient({
13
+ apiKey: API_KEY,
14
+ appName: "apex-client.test.ts",
15
+ });
16
+ // Create DeepResearch instance
17
+ const deepResearch = new DeepResearch_1.DeepResearch(client);
18
+ // Create test parameters, enter all DeepResearchJobParams fields for coverage
19
+ const params = {
20
+ messages: [
21
+ {
22
+ role: "user",
23
+ content: `Can you propose a mechanism by which a decentralized network
24
+ of AI agents could achieve provable alignment on abstract ethical principles
25
+ without relying on human-defined ontologies or centralized arbitration?`,
26
+ },
27
+ ],
28
+ model: "Default",
29
+ samplingParameters: {
30
+ temperature: 0.7,
31
+ topP: 0.95,
32
+ maxNewTokens: 100,
33
+ doSample: false,
34
+ },
35
+ seed: 42,
36
+ uids: [1, 2, 3],
37
+ };
38
+ // Submit the job
39
+ const response = await deepResearch.createJob(params);
40
+ // Verify response structure
41
+ expect(response).toBeDefined();
42
+ expect(typeof response.jobId).toBe("string");
43
+ expect(typeof response.status).toBe("string");
44
+ expect(typeof response.createdAt).toBe("string");
45
+ expect(typeof response.updatedAt).toBe("string");
46
+ // Log response for debugging
47
+ console.log("Create Job Response:", response);
48
+ }, 30000);
49
+ it("should get deep researcher job results", async () => {
50
+ // Create ApexClient
51
+ const client = new Client_1.ApexClient({
52
+ apiKey: API_KEY,
53
+ appName: "apex-client.test.ts",
54
+ });
55
+ // Create DeepResearch instance
56
+ const deepResearch = new DeepResearch_1.DeepResearch(client);
57
+ // First create a job. Use simple inputs as job creation is tested in the previous test.
58
+ const createParams = {
59
+ messages: [
60
+ {
61
+ role: "user",
62
+ content: `Can you propose a mechanism by which a decentralized network
63
+ of AI agents could achieve provable alignment on abstract ethical principles
64
+ without relying on human-defined ontologies or centralized arbitration?`,
65
+ },
66
+ ],
67
+ };
68
+ const createResponse = await deepResearch.createJob(createParams);
69
+ const jobId = createResponse.jobId;
70
+ // Then get the results
71
+ const response = await deepResearch.getJobResults(jobId);
72
+ // Verify response structure
73
+ expect(response).toBeDefined();
74
+ expect(response.jobId).toBe(jobId); // Job ID should match the one from the create response
75
+ expect(typeof response.status).toBe("string");
76
+ expect(typeof response.jobId).toBe("string");
77
+ expect(typeof response.createdAt).toBe("string");
78
+ expect(typeof response.updatedAt).toBe("string");
79
+ expect(Array.isArray(response.result)).toBe(true);
80
+ // Log response for debugging
81
+ console.log("Get Job Results Response:", response);
82
+ }, 60000); // Longer timeout for this test as it involves multiple API calls
83
+ });
@@ -1,11 +1,11 @@
1
- import { ApexServiceClient, ChatCompletionRequest as GeneratedChatCompletionRequest, ChatCompletionResponse, ChatCompletionChunkResponse, WebRetrievalRequest as GeneratedWebRetrievalRequest, WebRetrievalResponse, ChatMessage } from "../../generated/apex/v1/apex";
1
+ import { ApexServiceClient, ChatCompletionRequest as GeneratedChatCompletionRequest, ChatCompletionResponse, ChatCompletionChunkResponse, WebRetrievalRequest as GeneratedWebRetrievalRequest, WebRetrievalResponse, ChatMessage, SubmitDeepResearcherJobResponse, GetDeepResearcherJobRequest, GetDeepResearcherJobResponse } 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";
5
5
  import { MarkFieldsOptional } from "../util.types";
6
6
  type ChatCompletionRequest = MarkFieldsOptional<GeneratedChatCompletionRequest, "uids">;
7
7
  type WebRetrievalRequest = MarkFieldsOptional<GeneratedWebRetrievalRequest, "uids">;
8
- export { ApexStream, WebRetrievalRequest, WebRetrievalResponse, ChatCompletionRequest, ChatMessage, };
8
+ export { ApexStream, WebRetrievalRequest, WebRetrievalResponse, ChatCompletionRequest, ChatMessage, SubmitDeepResearcherJobResponse, GetDeepResearcherJobRequest, GetDeepResearcherJobResponse, };
9
9
  interface ApexClientOptions extends BaseClientOptions {
10
10
  timeout?: number;
11
11
  }
@@ -41,4 +41,12 @@ export declare class ApexClient extends BaseClient {
41
41
  * Web retrieval API for searching the internet
42
42
  */
43
43
  webRetrieval: (params: WebRetrievalRequest) => Promise<WebRetrievalResponse>;
44
+ /**
45
+ * Submit a deep researcher job
46
+ */
47
+ submitDeepResearcherJob: (params: ChatCompletionRequest) => Promise<SubmitDeepResearcherJobResponse>;
48
+ /**
49
+ * Get a deep researcher job
50
+ */
51
+ getDeepResearcherJob: (params: GetDeepResearcherJobRequest) => Promise<GetDeepResearcherJobResponse>;
44
52
  }
@@ -33,10 +33,13 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.ApexClient = exports.ChatMessage = exports.WebRetrievalResponse = exports.ApexStream = void 0;
36
+ exports.ApexClient = exports.GetDeepResearcherJobResponse = exports.GetDeepResearcherJobRequest = exports.SubmitDeepResearcherJobResponse = exports.ChatMessage = exports.WebRetrievalResponse = exports.ApexStream = void 0;
37
37
  const apex_1 = require("../../generated/apex/v1/apex");
38
38
  Object.defineProperty(exports, "WebRetrievalResponse", { enumerable: true, get: function () { return apex_1.WebRetrievalResponse; } });
39
39
  Object.defineProperty(exports, "ChatMessage", { enumerable: true, get: function () { return apex_1.ChatMessage; } });
40
+ Object.defineProperty(exports, "SubmitDeepResearcherJobResponse", { enumerable: true, get: function () { return apex_1.SubmitDeepResearcherJobResponse; } });
41
+ Object.defineProperty(exports, "GetDeepResearcherJobRequest", { enumerable: true, get: function () { return apex_1.GetDeepResearcherJobRequest; } });
42
+ Object.defineProperty(exports, "GetDeepResearcherJobResponse", { enumerable: true, get: function () { return apex_1.GetDeepResearcherJobResponse; } });
40
43
  const grpc = __importStar(require("@grpc/grpc-js"));
41
44
  const BaseClient_1 = require("../BaseClient");
42
45
  const Stream_1 = require("./Stream");
@@ -100,6 +103,36 @@ class ApexClient extends BaseClient_1.BaseClient {
100
103
  });
101
104
  });
102
105
  };
106
+ /**
107
+ * Submit a deep researcher job
108
+ */
109
+ this.submitDeepResearcherJob = async (params) => {
110
+ const client = this.createGrpcClient();
111
+ return new Promise((resolve, reject) => {
112
+ client.submitDeepResearcherJob({ ...params, uids: params.uids ?? [] }, (error, response) => {
113
+ if (error) {
114
+ reject(error);
115
+ return;
116
+ }
117
+ resolve(response);
118
+ });
119
+ });
120
+ };
121
+ /**
122
+ * Get a deep researcher job
123
+ */
124
+ this.getDeepResearcherJob = async (params) => {
125
+ const client = this.createGrpcClient();
126
+ return new Promise((resolve, reject) => {
127
+ client.getDeepResearcherJob(params, (error, response) => {
128
+ if (error) {
129
+ reject(error);
130
+ return;
131
+ }
132
+ resolve(response);
133
+ });
134
+ });
135
+ };
103
136
  this.defaultTimeout = options.timeout || 60;
104
137
  this._grpcClient = grpcClient;
105
138
  }
@@ -0,0 +1,28 @@
1
+ import { ApexClient } from "./Client";
2
+ import { ChatMessage, SamplingParameters, SubmitDeepResearcherJobResponse, GetDeepResearcherJobResponse } from "../../generated/apex/v1/apex";
3
+ /** interface for input parameters that can be defined by the user */
4
+ export interface DeepResearchJobParams {
5
+ /** The messages to generate completions for */
6
+ messages: ChatMessage[];
7
+ /** The miner UIDs that will be used to generate the completion */
8
+ uids?: number[];
9
+ /** The LLM name to use for the completion */
10
+ model?: string;
11
+ /** The seed to use for the completion */
12
+ seed?: number;
13
+ /** The sampling parameters to use for the completion */
14
+ samplingParameters?: SamplingParameters;
15
+ }
16
+ export declare class DeepResearch {
17
+ private client;
18
+ private readonly defaultSamplingParameters;
19
+ constructor(client: ApexClient);
20
+ /**
21
+ * Create a deep research job with proper defaults
22
+ */
23
+ createJob(params: DeepResearchJobParams): Promise<SubmitDeepResearcherJobResponse>;
24
+ /**
25
+ * Get the status and results of a deep research job
26
+ */
27
+ getJobResults(jobId: string): Promise<GetDeepResearcherJobResponse>;
28
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeepResearch = void 0;
4
+ class DeepResearch {
5
+ constructor(client) {
6
+ // Default sampling parameters for deep research
7
+ this.defaultSamplingParameters = {
8
+ temperature: 0.7,
9
+ topP: 0.95,
10
+ maxNewTokens: 8192,
11
+ doSample: false,
12
+ };
13
+ this.client = client;
14
+ }
15
+ /**
16
+ * Create a deep research job with proper defaults
17
+ */
18
+ async createJob(params) {
19
+ const request = {
20
+ // User configurable fields
21
+ messages: params.messages,
22
+ uids: params.uids ?? [], // Default to empty array if not provided
23
+ model: params.model,
24
+ seed: params.seed,
25
+ samplingParameters: params.samplingParameters ?? this.defaultSamplingParameters,
26
+ // Required internal fields for Deep Researcher
27
+ task: "InferenceTask",
28
+ mixture: false,
29
+ inferenceMode: "Chain-of-Thought",
30
+ stream: true,
31
+ };
32
+ return this.client.submitDeepResearcherJob(request);
33
+ }
34
+ /**
35
+ * Get the status and results of a deep research job
36
+ */
37
+ async getJobResults(jobId) {
38
+ return this.client.getDeepResearcherJob({ jobId });
39
+ }
40
+ }
41
+ exports.DeepResearch = DeepResearch;
@@ -1,2 +1,3 @@
1
1
  export * from "./Stream";
2
2
  export * from "./Client";
3
+ export * from "./DeepResearch";
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./Stream"), exports);
18
18
  __exportStar(require("./Client"), exports);
19
+ __exportStar(require("./DeepResearch"), exports);
19
20
  // Future exports from the apex package would go here
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "1.2.12";
1
+ export declare const VERSION = "1.2.13";
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.12";
4
+ exports.VERSION = "1.2.13";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "macrocosmos",
3
- "version": "1.2.12",
3
+ "version": "1.2.13",
4
4
  "description": "TypeScript SDK package for Macrocosmos",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",